【问题标题】:How do I initialize a table view in edit / re-ordering mode?如何在编辑/重新排序模式下初始化表格视图?
【发布时间】:2015-04-09 20:31:03
【问题描述】:

我希望我的视图中的表格视图始终可以重新排序。我无法弄清楚这一点。我的表格视图中有行,但无法显示重新排序句柄。

对于表格视图原型单元格,我确保在 Indentation > "Shows Re-order Controls" 中有一个检查,但这没有做任何事情。

这就是我整个班级的样子:

class ViewController: UIViewController {
    ...

    @IBOutlet var currentTable: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        currentTable.editing = true
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return unitCategories.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
        cell.textLabel?.text = "\(unitCategories[indexPath.row])"
        return cell
    }

    /*func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
        return UITableViewCellEditingStyle.None
    }*/
}

有人可以帮我指出正确的方向吗?

【问题讨论】:

    标签: ios uitableview swift xcode6


    【解决方案1】:

    您需要实现这两个方法才能显示重新排序控件,

    func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
    
    }
    
    func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        return true
    }
    

    如头文件所述,

     func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool
    

    允许重新排序附件视图可选地显示为 特定行。默认情况下,仅在以下情况下才会显示重新排序控件 数据源实现:

    -tableView:moveRowAtIndexPath:toIndexPath:
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 2011-08-31
      • 1970-01-01
      相关资源
      最近更新 更多