Atu*_*tia 10 reload uitableview ios
我有一个问题,我有一个UITableViewController,当视图出现时,我进行一些异步计算,这将导致更新表中的特定行.
在viewWillAppear函数内部,我计算了需要更新的必要行,如下所示:
- (void)reloadPaths:(NSMutableDictionary *)bookingsDict
{
NSMutableArray* indexArray = [NSMutableArray array];
int i = 0;
for (NSString *dateKey in self.eventsToShow) {
NSMutableDictionary *venues = [bookingsDict objectForKey:dateKey];
if (venues) {
int j = 0;
NSArray *events = [self.eventsToShow objectForKey:dateKey];
for (DCTEvent *event in events) {
NSString *venueIdString = [NSString stringWithFormat:@"%@", event.eventVenueId];
if ([venues objectForKey:venueIdString]) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
[indexArray addObject:indexPath];
}
j++;
}
}
i++;
}
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
}
Run Code Online (Sandbox Code Playgroud)
但是我注意到cellForRowAtIndexPath函数永远不会被调用,并且单元格没有正确更新.知道问题可能是什么吗?
编辑:我刚刚注意到,如果我滚动出应该更新的单元格的视图,那么当我滚动回视图时它会更新.在视野中有没有办法让它更新?
小智 7
包裹它怎么样?
[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
以下是我发现的一些类似问题.
在reloadRowsAtIndexPaths之后不调用cellForRowAtIndexPath
UITableView的reloadRowsAtIndexPaths:(NSArray*)indexPaths除非你调用它两次,否则无法重新加载?
希望这可以帮助.
编辑:我认为您不indexindex检查部分可能是常量,因为您在遍历每个对象时增加:
- (void)reloadPaths:(NSMutableDictionary *)bookingsDict
{
NSMutableArray* indexArray = [NSMutableArray array];
int i = 0;
for (NSString *dateKey in self.eventsToShow) {
NSMutableDictionary *venues = [bookingsDict objectForKey:dateKey];
if (venues) {
int j = 0;
NSArray *events = [self.eventsToShow objectForKey:dateKey];
for (DCTEvent *event in events) {
NSString *venueIdString = [NSString stringWithFormat:@"%@", event.eventVenueId];
if ([venues objectForKey:venueIdString]) {
//changed here as section might be constant as i think it might be
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:0];
[indexArray addObject:indexPath];
}
j++;
}
}
i++;
}
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
}
Run Code Online (Sandbox Code Playgroud)
尝试这个 :
//your code here
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22064 次 |
| 最近记录: |