2015-09-08 48 views
0

除去細胞欲刪除tableViewController細胞,但問題是刪除下一小區 實施例: 數組:[1,2,3,4,5] 當我從表中刪除2,自動從數據庫從TableViewController

這裏刪除3的代碼是我的代碼:

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
    if editingStyle == .Delete { 
     array_prodacts.removeAtIndex(indexPath.row) 
     tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
     let currentCell = tableView.cellForRowAtIndexPath(indexPath) as! TableViewCell2 }} 

回答

1

問題是這裏array_prodacts.removeAtIndex(indexPath.row)因爲tableview是基於零的索引,以便你的陣列中的元件1的indexPath是0,2爲1, 3是2,4是3,5是4.因此刪除索引2 re在你的數組中刪除數值3(有索引2)

+0

是的,你是對的,但我該如何解決它? 我已經現在,但我正在尋找正確的代碼 –

+0

大概這將解決您的問題'array_prodacts.removeAtIndex(indexPath.row - 1)' –

+0

不工作可能 我之前嘗試它 –

相關問題