2017-05-29 15 views
-1

スウィフト3.0のiOSしようとすると、テーブルの行を削除するには、このコードを使用して10.xのNSInternalInconsistencyExceptionのtableView行削除

...

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 
    if editingStyle == UITableViewCellEditingStyle.delete { 
     print("DELETE \(indexPath)") 
     self.tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic) 


    } 
} 

これは、エラーメッセージで失敗?

2017-05-29 13:36:23.843228+0200[939:576777] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (9) must be equal to the number of rows contained in that section before the update (9), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).' 

これはボイラープレートのコードだけで十分ですか?私は赤いボタンをクリックする以上のことをしていませんか?

enter image description here

はい、私はここで見逃している何9.

があった墜落した私のコードでは、ここで3行が...あるのですか?ここで返されたindexPathをプリントアウトして、間違っていましたが、私が設定していないのを待ってください。この方法はありましたか?

DELETE [0,3]

+0

に削除する前に、データアレイ内の行を削除する必要があります。 –

+2

あなたはデータソース配列(**の前に 'deleteRows(at')を呼び出す前に項目を削除するために欠落しています。 – vadian

答えて

1

あなたは同様にあなたのデータモデルの行を削除する必要がtableView

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 
    if editingStyle == UITableViewCellEditingStyle.delete { 
     print("DELETE \(indexPath)") 
     yourArray.remove(at: indexPath.row) /* delete in data array */ 
     self.tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic) 
    } 
} 
関連する問題