从Detailview删除Tableview的行 [英] Delete Tableview's Row from Detailview
问题描述
我已在我的应用程序的详细视图中使用情节提要用于 UITableView
,我已将tableview传递到详细视图,以便能够根据某些操作删除此行,但会在错误下方给出提示
I have used storyboard in my application in my detail view for UITableView
i passed tableview to detail view to be able to delete this row depend on something action but give me below error
*** 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 (4) must be equal to the
number of rows contained in that section before the update (4),
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).'
推荐答案
如果删除表中的最后一行,则UITableView代码期望剩余0行.它调用您的 UITableViewDataSource
方法来确定还剩下多少.由于您有一个无数据"单元格,它返回1,而不是0.因此,当您删除表的最后一行时,请尝试调用 -insertRowsAtIndexPaths:withRowAnimation:
插入无数据"行
If you delete the last row in your table, the UITableView code expects there to be 0 rows remaining. It calls your UITableViewDataSource
methods to determine how many are left. Since you have a "No data" cell, it returns 1, not 0. So when you delete the last row in your table, try calling -insertRowsAtIndexPaths:withRowAnimation:
to insert your "No data" row.
您需要做的是:
// tell the table view you're going to make an update
[tableView beginUpdates];
// update the data object that is supplying data for this table
// ( the object used by tableView:numberOfRowsInSection: )
[dataArray removeObjectAtIndex:indexPath.row];
// tell the table view to delete the row
[tableView deleteRowsAtIndexPaths:indexPath
withRowAnimation:UITableViewRowAnimationRight];
// tell the table view that you're done
[tableView endUpdates];
(根据此链接,您应该避免 NSInternalInconsistencyException
.)
( According to this link , you should avoid NSInternalInconsistencyException
. )
这篇关于从Detailview删除Tableview的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!