を並べ替えること:私たちは、セルをクリックすると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 ")私はそれを見ます:
そして、私は行をコメント「tableSideLeft.isEditing = true」をあなたはそれを見ることができます:
問題は、私はラインを残す場合は、「tableSideLeft.isEditing = true」を私は変えることができるということですがテーブルの順序しかし、私は細胞を広げるという行動を消しています。しかし、私がその行をコメントしたままにしておくと、細胞を拡大することはできますが、細胞を交換することはできません。
どのように私はそれらの両方を行うことができます:)?
ありがとうございます!
ええでそれを行う方法の一例です!それは解決策です!ありがとう –