2017-06-30 19 views
0

を並べ替えること:私たちは、セルをクリックするとiOSの - 私はスウィフト3でアプリケーションを開発していますが、私はテーブルを作りたいので、私は、問題を抱えている拡張し、テーブルビュー

  • 拡大と見ますカスタムコンテンツ。
  • セルを選択すると、表が表示される順序を変更できます。

    class LeftSideViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 
    
    var selectedIndex = -1 
    //var menuItems:[String] = ["RGB","PCB", "PCD Zonificado","PCD Arbol","Target Sectors", "Variability Map"] 
    
    @IBOutlet weak var tableSideLeft: UITableView! 
    @IBAction func opacityDelivery(_ sender: UISlider) { 
    
        print(sender.value) 
    
    } 
    
    override func viewDidLoad() { 
        super.viewDidLoad() 
        tableSideLeft.isEditing = true 
    
    } 
    
    func numberOfSections(in tableView: UITableView) -> Int { 
        return 1 
    } 
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
         return snapShotsLegend.legendEntries[0].deliverables.count 
    } 
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    
         let cellIdentifier = "Cell" 
         let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! customCell 
    
    
         cell.firstViewLabel.text = snapShotsLegend.legendEntries[0].deliverables[indexPath.row].type 
         cell.secondViewLabel.text = "Option " + snapShotsLegend.legendEntries[0].deliverables[indexPath.row].type 
         cell.idDeliveryResponse.text = snapShotsLegend.legendEntries[0].deliverables[indexPath.row].options[0].id 
         cell.initialMaxDeliveryResponse.text = String(snapShotsLegend.legendEntries[0].deliverables[indexPath.row].options[0].initial_max_value) 
         cell.initialMinDeliveryResponse.text = String(snapShotsLegend.legendEntries[0].deliverables[indexPath.row].options[0].initial_min_value) 
         cell.maxRangeDeliveryResponse.text = String(snapShotsLegend.legendEntries[0].deliverables[indexPath.row].options[0].max_range) 
         cell.minRangeDeliveryResponse.text = String(snapShotsLegend.legendEntries[0].deliverables[indexPath.row].options[0].min_range) 
    
         cell.backgroundColor = UIColor.init(red: 170/255, green: 170/255, blue: 170/255, alpha: 1) 
         return cell 
    } 
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
        if(selectedIndex == indexPath.row){ 
         return 300 
        }else{ 
         return 60 
        } 
    } 
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
        if(selectedIndex == indexPath.row){ 
         selectedIndex = -1 
        }else { 
         selectedIndex = indexPath.row 
        } 
    
        self.tableSideLeft.beginUpdates() 
        self.tableSideLeft.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic) 
        self.tableSideLeft.endUpdates() 
    } 
    
    
    //MARK: FUNCTIONS ALLOWS REORDERING OF CELLS 
    func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { 
        return true 
    } 
    
    func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { 
        let item = snapShotsLegend.legendEntries[0].deliverables[sourceIndexPath.row] 
        snapShotsLegend.legendEntries[0].deliverables.remove(at: sourceIndexPath.row) 
        snapShotsLegend.legendEntries[0].deliverables.insert(item, at: destinationIndexPath.row) 
    } 
    
    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle { 
        return UITableViewCellEditingStyle.none 
    } 
    
    } 
    

    とカスタムセルは次のとおりです:

まあ、私は "伝説のクラス" のコードと "customCell" のいずれかを囲む

import UIKit 

class customCell: UITableViewCell { 

//MARK: OUTLETS VIEW 1 
@IBOutlet weak var firstView: UIView! 
@IBOutlet weak var firstViewLabel: UILabel! 
@IBOutlet weak var swichtActiveLayer: UISwitch! 

@IBOutlet weak var secondView: UIView! 
@IBOutlet weak var secondViewLabel: UILabel! 
@IBOutlet weak var secondHeightConstraint: NSLayoutConstraint! 
@IBOutlet weak var idDeliveryResponse: UILabel! 
@IBOutlet weak var minRangeDeliveryResponse: UILabel! 
@IBOutlet weak var maxRangeDeliveryResponse: UILabel! 
@IBOutlet weak var initialMinDeliveryResponse: UILabel! 
@IBOutlet weak var initialMaxDeliveryResponse: UILabel! 

@IBAction func sliderOpacity(_ sender: UISlider) { 

    print(sender.value) 
} 
//MARK: OUTLETS VIEW 2 
override func awakeFromNib() { 
    super.awakeFromNib() 
    // Initialization code 
} 

override func setSelected(_ selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 

    // Configure the view for the selected state 
} 

var showsDetails = false { 
    didSet { 
     secondHeightConstraint.priority = showsDetails ? 250 : 900 
    } 
} 

} 

私はセルを並べ替えることができます(uncoment行 "tableSideLeft.isEditing = true ")私はそれを見ます:

enter image description here そして、私は行をコメント「tableSideLeft.isEditing = true」をあなたはそれを見ることができます:

enter image description here

問題は、私はラインを残す場合は、「tableSideLeft.isEditing = true」を私は変えることができるということですがテーブルの順序しかし、私は細胞を広げるという行動を消しています。しかし、私がその行をコメントしたままにしておくと、細胞を拡大することはできますが、細胞を交換することはできません。

どのように私はそれらの両方を行うことができます:)?
ありがとうございます!

答えて

0

私はちょうど別の質問で昨夜拡大/縮小テーブルビューのセルへの回答を投稿しました。同様githubの上にリンクされているTheresのワーキングサンプルプロジェクト:順序を変更するよう

Dynamic Sizing and Collapsable TableViewCells

は、その通常はテーブルビューコントローラの「編集モード」に入る介して行われます。編集モードには、挿入、削除、並べ替えコントロールのサポートが含まれます。機能は主にビルド​​インで、ちょっとしたコードが必要です。

このモードに入るには、次の呼び出しを行います。

self.tableView.setEditing(editing, animated: animated) 

TableViewCellは、編集オプションを設定する場所です。あなたはプロトタイプのセルを選択すると、インターフェイスビルダーでは、あなたはインスペクタで次のように設定することができます。

  • 編集モードで表示するためのアクセサリー
  • 再順序表示するかどうかを
  • を編集するときにインデントするかどうかコントロール

最後の1つがチェックされていることを確認します。

Apple tableView.setEditing docsは、説明のまともな概要を示します。この記事で

+0

ええでそれを行う方法の一例です!それは解決策です!ありがとう –

関連する問題