拡張可能なヘッダービューを持つことができるUITableViewを作成しようとしています。あなたがヘッダビューの内側にボタンを押すと、以下の機能が実行されます:UITableViewのセル挿入エラー
func expandTheCell(_ sender: UIButton) {
self.tableView.beginUpdates()
if sender.isExpanded == false {
postsArray.append("Hello")
tableView.reloadData()
print("Array Count: \(postsArray.count)")
self.tableView.insertRows(at: [IndexPath.init(row: 0, section: sender.tag)], with: .fade)
} else {
print("test")
}
self.tableView.endUpdates()
}
これは、いくつかのテーブルビュー機能です:私は行を挿入しようとすると
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return postsArray.count
}
func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
は、私は次の取得しますエラー:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 1
どのようにしてセルを挿入できませんか?私は間違って何をしていますか?
'tableView.reloadData()'を削除してから、プログラムを実行してください。 – 3stud1ant3
まだ削除されていません。 –
も 'postsArray.append(" Hello ")'と書いておきます。エラーも? – 3stud1ant3