- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
NSFetchedResultsControllerDelegate 的文档提供了以下示例代码
- (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
UITableView *tableView = self.tableView;
switch(type) {
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView reloadSections:[NSIndexSet indexSetWithIndex:newIndexPath.section] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
当我创建一个新的 NSManagedObject 时,NSFetchedResultsChangeInsert 会触发(太棒了!)。当我更改属性值(用于单元格标题)时,NSFetchedResultsChangeUpdate 会触发。不幸的是,除非我重新加载表、部分或行,否则新标题不会自动显示。事实上,如果新名称导致结果集以不同方式排序,则 NSFetchedResultsChangeMove 会触发,并且一切正常,因为提供的代码会重新加载整个部分。
UITableView 有一个方法reloadRowsAtIndexPaths:withRowAnimation,所以我尝试在 NSFetchedResultsChangeUpdate 代码块下使用它。它确实有效......但是这个特定方法的文档读起来好像我不需要它(注意最后一行):
Reloading a row causes the table view to ask its data source for a new cell for that row. The table animates that new cell in as it animates the old row out. Call this method if you want to alert the user that the value of a cell is changing. If, however, notifying the user is not important—that is, you just want to change the value that a cell is displaying—you can get the cell for a particular row and set its new value.
是的,如果我记录正在发生的事情,当
[self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
在NSFetchedResultsChangeUpdate上调用,它能够检索最新的“名称”值并将其设置在单元格的textLabel中。除非我重新加载,否则该名称不会在单元格中呈现。即使我只是单击单元格,名称也会显示出来。请注意,要重新创建此行为,您必须创建一个新的托管对象,然后为其指定一个名称,使其在 NSFetchedResultsController 中排序为 FIRST。这样, NSFetchedResultsChangeMove 就不会触发(它确实有效,因为它重新加载了该部分)。
我错过了什么还是这是预期的行为? reloadRowsAtIndexPaths 的“讨论”让我相信我应该能够简单地设置单元格的 textLabel,而无需重新加载行、部分或表格。
最佳答案
您应该调用 [cell setNeedsLayout]
或/和 [cell setNeedsDisplay]
来刷新单元格,具体取决于单元格的实现。
如果你像我们通常那样组合 subview 的单元格,你依赖于-layoutSubviews
,所以你应该调用[cell setNeedsLayout]
。
如果直接使用-drawRect:
绘制单元格,则应该调用[cell setNeedsDisplay]
。
如果您同时使用合成和绘图,则应该同时调用两者。
关于iphone - NSFetchedResultsControllerDelegate 'ChangeUpdate' 行为是否已损坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1326408/
我无法弄清楚为什么当我向底层数据存储添加数据时,NSFetchedResultsControllerDelegate 方法没有触发。如果我重新启动 iPhone 应用程序,数据会立即显示。 我已经子类
我是 iOS (Swift) 的新手,正在尝试了解 NSFetchedResultsControllerDelegate 机制。我特别不明白的是 NSFetchedResultsChangeType
我的 viewWillAppear 方法中有这个 [RPCoreData getFetchedControllerForCategoryDiscoverDelegate:self completio
NSFetchedResultsControllerDelegate 的文档提供了以下示例代码 - (void)controller:(NSFetchedResultsController *)con
我想在 CollectionViewController 中使用 NSFetchedResultsControllerRelegate。因此,我只是更改了 CollectionView 的 Table
我在 Xcode 收到以下警告,但不知道原因。欢迎任何帮助。 Assigning to 'id' from incompatible type 'CollapsableTableViewViewCo
据我了解,NSFetchedResultsController 负责将数据从托管对象上下文同步到 TableView Controller 。代表在这里的作用是什么?我阅读了苹果文档并没有得到它。请简
我正在尝试为实现 NSFetchedResultsControllerDelegate protocol 的 View Controller 编写单元测试。 .实现的第一个测试(在此 View Con
问候 Stack 的公民,当尝试覆盖“controllerDidChangeContent”时,我得到“方法不会覆盖其父类(super class)中的任何方法”。该 stub 由自动完成处理程序生成
在阅读了大量 Core Data 框架的文档和示例之后,我仍然不太明白。发生的情况是我有点理解示例代码或文档的部分内容,但通常无法将其放入更大的图片中。第二次读同样的代码,和第一次一样,还是需要很多时
这是我对委托(delegate)的实现: func controllerWillChangeContent(_ controller: NSFetchedResultsController) {
我正在使用一些在 UITableView 中实现 NSFetchedResultsControllerDelegate 的样板代码。当我执行远离 TableView 的 segue 时,将调用此委托(
我正在结合 NSFetchedResultsController 实现 UITableViewController。当 UITableViewController 实例化时,基于用户在前一个 Cont
前提:我有一个符合NSFetchedResultsControllerDelegate的UITableViewController。我还有一个获取结果 Controller 和托管对象上下文作为 Co
这是我的代码: class FetchResultControllerDataProvider: NSObject, NSFetchedResultsControllerDelegate {
我目前正在开发一个基于 CoreData 的 iPhone 应用程序,它的 map View 将从 生成其注释。 NSFetchedResultsController . map View 的想法是它
我有一个示例应用程序,它有一个带有单个属性的 NSManagedObject(我们称类为 CustomObject)。 该应用程序有一个简单的用户界面,由一个带有 UICollectionView 的
我正在尝试在 UITableView 中使用 NSFetchedResultsController。但是由于某些原因,当我添加一个新条目时,NSFetchedResultsControllerDele
我在 .h 中定义了一个 UITableViewController,如下所示: @interface PartsSearchViewController : UITableViewControlle
我喜欢使用 CoreData 根据数据库中的创建日期填充记录,所以我使用 NSFetchedResultsControllerDelegate 来获得良好的功能,正如我添加的那样: @interfac
我是一名优秀的程序员,十分优秀!