繁体   English   中英

如何重新加载 tableview 的特定部分

[英]how to reload tableview's particular section

我的 tableview 中有 56 个部分,我将当前选择的部分编号存储在名为“activeTimeSlot”的整数变量中。 如何使用以下方法重新加载当前选择的部分。 我正在这样做

 [self.tblView reloadSections:[NSIndexSet indexSetWithIndex:activeTimeSlot] withRowAnimation:UITableViewRowAnimationAutomatic];

但我观察到这样做是为所有部分调用 tableview 的以下数据源方法,即重新加载所有部分。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

我不确定如何使用 NSIndexSet 以及如何使用 NSIndexSet 重新加载 1 个以上的部分。

如果你想更新多个部分,那么你可以这样做。

NSMutableIndexSet *indetsetToUpdate = [[NSMutableIndexSet alloc]init];

[indetsetToUpdate addIndex:previousSection]; // [indetsetToUpdate addIndex:<#(NSUInteger)#>] 
// You can add multiple indexes(sections) here.

[detailTableView reloadSections:indetsetToUpdate withRowAnimation:UITableViewRowAnimationFade];

这用于更新多个部分,对我来说效果很好。

正如我从您的评论中看到的,您正在检查方法的调用

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

找出它正在重新加载每个部分。 但可能出于内部原因,所有部分都调用了该方法。 如果您尝试记录实际重新加载了哪些行,您会看到一切正常。 放一个

NSLog(@"Section %d", indexPath.section);

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

并看到仅重新加载所选部分中的行。

PS:忘了说:您的解决方案已经正确。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM