鍍金池/ 問答/iOS  網(wǎng)絡(luò)安全/ 關(guān)于TableView代碼正確可是無法實(shí)現(xiàn)移動(dòng)行效果的問題

關(guān)于TableView代碼正確可是無法實(shí)現(xiàn)移動(dòng)行效果的問題

TableView代碼無誤,可無法實(shí)現(xiàn)效果。

@IBAction func EditButton(_ sender: Any) {
       
        ListTableView.isEditing = !ListTableView.isEditing
        switch ListTableView.isEditing{
        case true:
            EditButton.title = "done"
        case false:
            EditButton.title = "edit"
            
        }
    }
    ···
    //移動(dòng)行
    //是否可編輯
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
     // 編輯模式
    override func setEditing(_ editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
        ListTableView.setEditing(editing, animated: true)
    
    //允許重新排序單元格,如果返回否則無法重新排序
    func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    //執(zhí)行行重排的操作
    func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath){
        
        let item = Array[sourceIndexPath.row]
        
        Array.remove(at: sourceIndexPath.row)
        Array.insert(item, at: destinationIndexPath.row)
    }
    
    override func didReceiveMemoryWarning() {
    }

}

這個(gè)是此方法的參考鏈接:
How To Reorder/Rearrange Table View Cells In Xcode 8 (Swift 3)

同時(shí)也參考了道長的swift30個(gè)項(xiàng)目里的todo里的方法,參考鏈接:
soapyigu/Swift-30-Projects/Project 04 - Todo/Todo.xcodeproj/

可依然無法實(shí)現(xiàn)效果。

這兩個(gè)方法在我的GitHub里,歡迎評(píng)論補(bǔ)充。
FelixXiong/Swift-Function-code-library-example/TableView相關(guān).md

關(guān)于此問題之前的問題:
UITableView的移動(dòng)行的問題
可是并未解決效果。

回答
編輯回答
敢試

設(shè)置UITableView的editingtrue

tableView.setEditing(true, animated: true)

然后重寫sourceIndexPath方法

func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath){
        
}
2017年2月7日 02:54