Vis*_*ngh 5 objective-c uitableview ios
我的tableview中有56个部分,我正在存储当前在名为"activeTimeSlot"的整数变量中选择的部分编号.如何使用以下方法重新加载当前选定的部分.我这样做
[self.tblView reloadSections:[NSIndexSet indexSetWithIndex:activeTimeSlot] withRowAnimation:UITableViewRowAnimationAutomatic];
Run Code Online (Sandbox Code Playgroud)
但我观察到这样做是为所有部分调用tableview的下面数据源方法,即重新加载所有部分.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
我不知道如何使用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];
Run Code Online (Sandbox Code Playgroud)
这用于更新多个部分,它对我来说很好.
希望它会对你有所帮助.
正如我从您的评论中看到的,您正在检查该方法的调用
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
找出它正在重新加载每个部分。但可能出于内部原因,所有部分都调用该方法。如果您尝试记录实际重新加载的行,您会发现一切都很好。放一个
NSLog(@"Section %d", indexPath.section);
Run Code Online (Sandbox Code Playgroud)
在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
并看到仅重新加载所选部分中的行。
PS:忘了说:你的解决方案已经是正确的。
| 归档时间: |
|
| 查看次数: |
8950 次 |
| 最近记录: |