ios – UITableView reloadData不重新加载

ios – UITableView reloadData不重新加载,第1张

概述我很困惑为什么reloadData不会重新加载tableview.它不会调用numberOfRowsInSection … fetchedResultsController在将新数据保存到核心数据后确实获得了新行 在将新数据添加到tableview之前 2011-12-29 19:09:08:213 CaveConditions[56423:71939] FRC 170 在viewWillAppe 我很困惑为什么reloadData不会重新加载tablevIEw.它不会调用numberOfRowsInSection …

fetchedResultsController在将新数据保存到核心数据后确实获得了新行

在将新数据添加到tablevIEw之前

2011-12-29 19:09:08:213 CaveConditions[56423:71939] FRC 170

在vIEwWillAppear之后并添加数据

2011-12-29 19:09:35:908 CaveConditions[56423:71939] FRC NEW 171

在调用reloadData之前,tableVIEw(atableVIEw)不是nil

2011-12-29 19:18:27:334 CaveConditions[56525:71939] tableVIEw: <UItableVIEw: 0x9c12000; frame = (0 0; 320 367); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x751cbb0>; contentOffset: {0,0}>

一旦我重新启动应用程序,它就会显示新内容…我正在使用Storyboard并完成了tablevIEw和委托/数据源之间的所有连接并多次检查它. Class是一个UIVIEwController.

- (voID)vIEwWillAppear:(BOol)animated{[super vIEwWillAppear:animated];self.fetchedResultsController = nil;NSError *error;if (![[self fetchedResultsController] performFetch:&error]) {    // Update to handle the error appropriately.    NSLog(@"Unresolved error %@,%@",error,[error userInfo]);}ID <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:0];NSLog(@"FRC NEW %d",[sectionInfo numberOfObjects]);[self.atableVIEw reloadData];}

不知道这里有什么问题……有什么想法吗?

编辑:

我懒得加载FRC

- (NSFetchedResultsController *)fetchedResultsController {if (!fetchedResultsController){    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];    if (isnormalCell)    {        fetchRequest.entity = [NSEntityDescription entityForname:@"Condition" inManagedobjectContext:self.context];        fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"diveDate" ascending:NO]];                fetchRequest.predicate = [nspredicate predicateWithFormat:@"cave = %@",cave];    } else    {        fetchRequest.entity = [NSEntityDescription entityForname:@"Condition" inManagedobjectContext:self.context];        fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"insertDate" ascending:NO]];        fetchRequest.returnsdistinctResults = YES;    }    fetchRequest.fetchBatchSize = 20;    fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest                                                                    managedobjectContext:context                                                                      sectionnameKeyPath:nil                                                                               cachename:nil];    fetchedResultsController.delegate = self;}return fetchedResultsController;}

这里有一些代码

- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {static Nsstring *CellIDentifIEr;if (!isnormalCell)    CellIDentifIEr = @"conditionCellReport";else    CellIDentifIEr = @"conditionCell";UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr];if (cell == nil) {    cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleSubTitle reuseIDentifIEr:CellIDentifIEr];}// Set up the cell...[self configureCell:cell atIndexPath:indexPath];return cell;}- (voID)configureCell:(UItableVIEwCell *)cell atIndexPath:(NSIndexPath *)indexPath {    Condition *condition = [fetchedResultsController objectAtIndexPath:indexPath];    ConditionCell *conCell = (ConditionCell *)cell;     // reset cell tag which normally contains the ConditionID    conCell.tag = 0;    conCell.img.image = nil;    conCell.lineLabel.text = [condition.line valueForKey:@"line"];    conCell.flowProgress.progress = [[condition.flow valueForKey:@"flowValue"] floatValue];    conCell.percolationProgress.progress = [[condition.percolation valueForKey:@"percolationValue"] floatValue];    conCell.sedimentProgress.progress = [[condition.sediment valueForKey:@"sedimentValue"] floatValue];    conCell.visProgress.progress = [[condition.visibility valueForKey:@"visValue"] floatValue] / 25;    conCell.tag = [condition.ccID intValue];...

发现另一个问题.保存数据并在尝试滚动时返回到tablevIEw它只显示白色单元格..它也不会重新加载旧单元格.

解决方法 好!我发现了这个问题.我使用的是beginUpdates和endUpdates,而不是reloadData.非常感谢您的帮助!我从 NSFetchedResultsControllerDelegate Reference获得了信息

- (voID)controllerWillChangeContent:(NSFetchedResultsController *)controller{    [self.tableVIEw beginUpdates];}- (voID)controllerDIDChangeContent:(NSFetchedResultsController *)controller{    [self.tableVIEw endUpdates];}
总结

以上是内存溢出为你收集整理的ios – UITableView reloadData不重新加载全部内容,希望文章能够帮你解决ios – UITableView reloadData不重新加载所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1017489.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存