【发布时间】:2016-11-08 11:53:15
【问题描述】:
我的ViewController 上有一个UITableView 它有n 的部分,我的第一部分总是显示我的愿望清单 产品(仅基于显示愿望清单 在SettingsController 中启用了选项) 每次我在DetailViewController 上将产品添加到我的愿望清单 时,我都会触发NSNotificatiion 到我的ViewController它将在哪里获取 Wishlist 记录。
我的numberOfRowsInSection: 总是返回1,因为它是一个UITableView + UICollectionView 组合来产生水平+垂直滚动。
所以,我正在重新加载我的部分,如下所示,
if (isWishListSectionReloadRequires) {
NSArray *deleteIndexPaths = [NSArray arrayWithObjects:
[NSIndexPath indexPathForRow:0 inSection:0],
nil];
NSArray *insertIndexPaths = [NSArray arrayWithObjects:
[NSIndexPath indexPathForRow:0 inSection:0],
nil];
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationNone];
[tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
} else {
[tableView reloadData];
}
但是,我正面临崩溃,
-[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1054 2016-11-04 04:25:15.921 估计 [9025:c07] 中的断言失败 *** 由于应用程序终止未捕获的异常“NSInternalInconsistencyException”,原因:“无效更新:无效的节数。更新后表视图中包含的节数(10)必须等于更新前表视图中包含的节数(10),加上或减去插入或删除的节数(1插入,1已删除)
谁能告诉我可能是什么原因?任何想法将不胜感激!
【问题讨论】:
-
您是否相应地更新了数据源?我的意思是一个部分的行数等?
-
@KrishnaChaitanyaAmjuri 如何手动更新数据源?
-
试试 - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation,而不是删除和插入。
-
您是否尝试通过调用tableview 的
reloadSections方法重新加载第一部分? -
是的,我试过了。它崩溃了
标签: ios objective-c uitableview uiviewcontroller