2016-08-03 12 views
1

私は2 sections1/59の行を持っています。 私は行を削除するので(0行では0行を取得)、このクラッシュを取得しました(また、ブレークポイントは-[UITableView deleteRowsAtIndexPaths:withRowAnimation:]となります)。この1の削除方法を知ることはできません)が計算されます。UITableViewセクション削除の問題

Invalid update: invalid number of sections. The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (2), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted) 

私はこのメッセージが表示されますが、すべてのセクションのない削除はありません、-[UITableView deleteSections:withRowAnimation:]でのブレークポイントは動作しません。

アイデア/提案はありますか?

ありがとうございます!

+0

あなたが試したコードをさらに表示してください。 –

+0

このリンクをチェックするhttp://stackoverflow.com/questions/29813878/invalid-update-invalid-number-of-rows-in-section – gurmandeep

+1

beginUpdates/endUpdatesの間にreloadDataの呼び出しがありません – Aleksandr

答えて

-1

私はあなたのコードが表示されないので、何が起こっていると思いますが、わかりません。 テーブルの行またはセクションを削除する場合の手順について説明します。

私はあなたがセクションと行と他の配列を持つ配列を持っていることを提案します。

1 - あなたが行の配列から行を削除する必要があります

arrayRows.removeAtIndex(indexRow) 

2 - (necesaryである場合)は、セクションのアレイからセクションを削除する必要があり:

arraySections.removeAtIntex(indexSection) 

3 - 次のコードを使用してテーブルから行を削除する瞬間です:

tableView.beginUpdates() 
tableView.deleteRowsAtIndexPaths(indexRow, withRowAnimation: UITableViewRowAnimation.Fade) 
//If you want delete sections, firstly you must delete all rows of this section 
tableView.deleteSections(indexSection, withRowAnimation: UITableViewRowAnimation.Fade) 
tableView.endUpdates() 

//After this, you must reload data of table 
tableView.reloadData() 

PD:あなたのメソッドnum berOfRowsInSectionとnumberOfSectionsInTableViewは、行とセクションの配列からデータを取得します。このように:

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return arraySections.count 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    //Return array of rows of section 
    return arrayRows.count 
} 

私はそれが助けて欲しいです!

ご不明な点がありましたら教えてください。他の方法でお手伝いします。

関連する問題