ios – NSFetchedResultsController – TableView中不完整的UI更新

ios – NSFetchedResultsController – TableView中不完整的UI更新,第1张

概述我正在使用NSFetchedResultsController来刷新表视图的数据.数据本身是通过在后台运行的 XML解析器提供的.解析器完成后,它会将数据保存到自己的上下文中. NSFetchedResultsController立即获取这些更改并开始调用 – (void)控制器:didChangeObject:atIndexPath:forChangeType:newIndexPath:每个更新 我正在使用NSFetchedResultsController来刷新表视图的数据.数据本身是通过在后台运行的 XML解析器提供的.解析器完成后,它会将数据保存到自己的上下文中. NSFetchedResultsController立即获取这些更改并开始调用 – (voID)控制器:dIDChangeObject:atIndexPath:forChangeType:newIndexPath:每个更新元素的委托方法.这也很快,在日志文件中看起来完全正常.

但是,在 – (voID)controllerDIDChangeContent:我调用UItableVIEw的 – (voID)endUpdates.然后我在屏幕上看到更新动画,但在所有单元格中,在最后一个只有一半可见的单元格旁边,唯一可见的是单元格左侧的图像.所有文字标签都不可见.它需要大约5到10秒,然后所有标签都可见.

但是,如果我忽略NSFetchedResultsController的所有委托调用,只需调用[self.tableVIEw reloadData] on – (voID)controllerDIDChangeContent:一切正常,没有问题.内容立即存在.

有谁知道我在这里做错了什么?分析器显示主线程基本上什么都不做.除了调度到表视图的事件之外,还可以正确处理触摸事件.这些都没有处理.看起来表格视图正忙于做一些认真的工作,但我真的不知道那可能是什么,因为动画已经完成了.

这是我对NSFetchedResultsControllerDelegate的实现:

- (voID)controllerWillChangeContent:(NSFetchedResultsController *)controller {    NSLog(@"%s",__PRETTY_FUNCTION__);    [self.tableVIEw beginUpdates];}- (voID)controller:(NSFetchedResultsController *)controller dIDChangeSection:(ID <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {    NSLog(@"%s",__PRETTY_FUNCTION__);    switch(type) {        case NSFetchedResultsChangeInsert:            [self.tableVIEw insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UItableVIEwRowAnimationautomatic];            break;        case NSFetchedResultsChangeDelete:            [self.tableVIEw deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UItableVIEwRowAnimationautomatic];            break;    }}- (voID)controller:(NSFetchedResultsController *)controller dIDChangeObject:(ID)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath*)newIndexPath {    NSLog(@"%s",__PRETTY_FUNCTION__);    UItableVIEw* tableVIEw = self.tableVIEw;    switch(type) {        case NSFetchedResultsChangeInsert:            [tableVIEw insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UItableVIEwRowAnimationautomatic];            break;        case NSFetchedResultsChangeDelete:    [tableVIEw deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UItableVIEwRowAnimationautomatic];            break;        case NSFetchedResultsChangeUpdate:    [(NewsItemCell*)[tableVIEw cellForRowAtIndexPath:indexPath] updateWithNews:[self.fetchedResultsController objectAtIndexPath:indexPath]];            break;        case NSFetchedResultsChangeMove:            [tableVIEw deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UItableVIEwRowAnimationautomatic];            [tableVIEw insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UItableVIEwRowAnimationautomatic];            break;    }}- (voID)controllerDIDChangeContent:(NSFetchedResultsController *)controller {    NSLog(@"%s",__PRETTY_FUNCTION__);    [self.tableVIEw endUpdates];}

这是我的单元格布局的代码:

- (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw {    return self.fetchedResultsController.sections.count;}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section {    ID<NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController.sections objectAtIndex:section];    return sectionInfo.numberOfObjects;}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {    News* model = [self.fetchedResultsController objectAtIndexPath:indexPath];    NewsItemCell* cell = (NewsItemCell*)[tableVIEw dequeueReusableCellWithIDentifIEr:NewsCellReuseIDentifIEr];    [cell updateWithNews:model];    cell.accessoryType = (model.content ? UItableVIEwCellAccessorydisclosureIndicator : UItableVIEwCellAccessoryNone);    return cell;}

这个细胞非常基本的更新:

- (voID)updateWithNews:(News*)news {    Nsstring* dateString = [[NSDateFormatter outputDateFormatter] stringFromDate:news.date];    self.headlineLabel.text = (news.headline ? news.headline : NSLocalizedString(@"<NewsNoheadlineReplacement>",nil));    self.MetaInfolabel.text = [Nsstring stringWithFormat:NSLocalizedString(@"<NewsMetaInfoFormatDate>",nil),(dateString ? dateString : (NSLocalizedString(@"<NewsNoDateReplacement>",nil)))];    self.readindicatorVIEw.hIDden = (news.read != nil && [news.read compare:news.parsingDate] == NSOrderedDescending);}

占位符字符串也未显示.标签完全是空的.只有图像可见!

解决方法 我先检查的事情:

>确保您的提取未在其他线程中执行>确保你的提取很快,如果它太慢也可能是原因

总结

以上是内存溢出为你收集整理的ios – NSFetchedResultsController – TableView中不完整的UI更新全部内容,希望文章能够帮你解决ios – NSFetchedResultsController – TableView中不完整的UI更新所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存