gpt4 book ai didi

ios - 我如何刷新特定部分?

转载 作者:行者123 更新时间:2023-11-29 00:36:25 28 4
gpt4 key购买 nike

我的 ViewController 上有一个 UITableView 它有 n 个部分,我的第一个部分总是显示我的愿望 list 产品 (仅基于 SettingsController 中启用的显示 Wishlist 选项) 每次我将产品添加到我的Wishlist 在我的 DetailViewController 上我正在触发一个 NSNotificatiion 到我的 ViewController 它将获取 Wishlist 记录。

我的 numberOfRowsInSection: 总是返回 1 因为它是一个 UITableView + UICollectionView 组合产生Horizo​​ntal + Vertial 滚动。

所以,我正在按照以下方式重新加载我的部分,

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];
}

但是,我正面临崩溃,

Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1054 2016-11-04 04:25:15.921 estimation[9025:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (10) must be equal to the number of sections contained in the table view before the update (10), plus or minus the number of sections inserted or deleted (1 inserted, 1 deleted)

谁能告诉我是什么原因?任何想法将不胜感激!!

最佳答案

您可以改用 UITableView 的 reloadSections 方法。

Objective-C

NSRange range = NSMakeRange(0, 1);
NSIndexSet *section = [NSIndexSet indexSetWithIndexesInRange:range];
[self.tableView reloadSections:section withRowAnimation:UITableViewRowAnimationNone];

swift

tableView.reloadSections(NSIndexSet(index: 2), withRowAnimation: .None)

关于ios - 我如何刷新特定部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40486263/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com