TableView:UITableView的移动行的问题

在创建移动行的代码时,
加粗的两行报错,根据教程中使用的确实是这个方法:

 func tableView(_ tableView: UITableView, moveRowAtsourceIndexPath: IndexPath, toIndexPath destinationIndexPath: IndexPath){

代码如下:

 //是否可编辑
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    //允许重新排序单元格,如果返回否则无法重新排序
    func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    //从行~到行
    func tableView(_ tableView: UITableView, moveRowAtsourceIndexPath: IndexPath, toIndexPath destinationIndexPath: IndexPath){
        
        **let item = Array[sourceIndexPath.row]
        
        Array.remove(at: sourceIndexPath.row)**
        Array.insert(item, atIndex: destinationIndexPath.row)
    }
       
        func didReceiveMemoryWarning() {
    }

问朋友说是没有sourceIndexPath这个值。

参考链接:How To Reorder/Rearrange Table View Cells In Xcode 8 (Swift 3)

阅读 2.8k
1 个回答

现在解决了,是因为自己该打空格的地方没有打空格。可是点击Edit依然没有出现可以移动操作的右边的按钮。
猜想也许是数据源的问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题