TableViewにセルで自分の投稿を表示しています。
投稿のデータはMySQLに保存しており、取得や編集のたびにAlamofireで通信しています。
質問したい点は、投稿のデータを削除したタイミングで、TableViewのセルも削除したいのですが、現状ではXcode側では以下のようなエラーが出ており、
Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (8) must be equal to the number of rows contained in that section before the update (8), 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).
ターミナル側では以下のようなエラーが出ています。
Started DELETE "/api/diaries/15" for ::1 at 2015-08-06 13:55:22 +0900
Processing by Api::DiariesController#destroy as /
Parameters: {"default"=>{"format"=>:json}, "id"=>"15"}
Unpermitted parameter: default
Diary Load (0.3ms) SELECT diaries
.* FROM diaries
WHERE diaries
.id
= 15 LIMIT 1
(0.1ms) BEGIN
SQL (0.2ms) DELETE FROM diaries
WHERE diaries
.id
= 15
(16.8ms) COMMIT
Rendered api/diaries/destroy.json.jbuilder (0.1ms)
Completed 200 OK in 23ms (Views: 3.6ms | ActiveRecord: 17.3ms)
TableViewのファイルのエラーの部分のコードは以下の通りです
lang
1override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 2 switch editingStyle { 3 case .Delete: 4 self.currentDiary = diaryStocks.myDiaries[indexPath.row] 5 DiaryStocks.removeDiary(currentDiary!) //Alamofireを使いHTTP通信 6 tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Middle) //この記述がある場合にエラーが起きます。 7 return 8 default: 9 return 10 } 11 }