NSFetchedResultController讲解
2015-08-24 19:52
225 查看
有关于coreData 中可以说为在外界的代码和Core Data进行打交道最为主要的类就是NSFetchedResultController,可以说是“中枢”,
起到了承上启下的作用。
它的一些相应的方法常用到的写如下,可供参考:
起到了承上启下的作用。
它的一些相应的方法常用到的写如下,可供参考:
#import <Foundation/Foundation.h> //接口 @protocol NSFetchedResultsControllerDelegate; //所需要的底层的两个对象 @class NSFetchRequest; //发送请求 @class NSManagedObjectContext; //上下文(通过请求上下文) //UItableView中相关联 NSFetchedResultsController //讲解:它工作在高层中的视图的原理:将一个“请求”和一个“上下文”作为其输入; //并在请求中的数据改变的时候调用相应的代理方法。 NSFetchRequest + NSManagedObjectContext —— NSFetchedResultsController ——> (获取的结果控制器委托(NSFetchedResultsControllerDelegate方法))(获取结果)——————>UItableView //这个获取结的果控制器对象私有属性 @interface NSFetchedResultsController : NSObject { @private NSFetchRequest *_fetchRequest; NSManagedObjectContext *_managedObjectContext; NSString *_sectionNameKeyPath; NSString *_sectionNameKey; NSString *_cacheName; void *_cache; struct _fetchResultsControllerFlags { unsigned int _sendObjectChangeNotifications:1; unsigned int _sendSectionChangeNotifications:1; unsigned int _sendDidChangeContentNotifications:1; unsigned int _sendWillChangeContentNotifications:1; unsigned int _sendSectionIndexTitleForSectionName:1; unsigned int _changedResultsSinceLastSave:1; unsigned int _hasMutableFetchedResults:1; unsigned int _hasBatchedArrayResults:1; unsigned int _hasSections:1; unsigned int _usesNonpersistedProperties:1; unsigned int _includesSubentities:1; unsigned int _reservedFlags:21; } _flags; id _delegate; id _sortKeys; id _fetchedObjects; id _sections; id _sectionsByName; id _sectionIndexTitles; id _sectionIndexTitlesSections; } //获取结果改变的类型 typedef NS_ENUM(NSUInteger, NSFetchedResultsChangeType) { NSFetchedResultsChangeInsert = 1, //插入 NSFetchedResultsChangeDelete = 2, //删除 NSFetchedResultsChangeMove = 3, //移动 NSFetchedResultsChangeUpdate = 4 //更新 } NS_ENUM_***AILABLE(NA,3_0); - (id)initWithFetchRequest:(NSFetchRequest *)fetchRequest managedObjectContext: (NSManagedObjectContext *)context sectionNameKeyPath:(NSString *)sectionNameKeyPath cacheName:(NSString *)name; ##################下面是相应的代理方法 #pragra mark NSFetchedResultsControllerDelegate @protocol NSFetchedResultsControllerDelegate @optional - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller; //就是这个更新,将会通过tableView中的的-beginUpdates方法来更行表图的显示。 @optional - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller; //已经改变了之后 //这个事相对于 “行” 来操作的 @optional - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath; //这个方法是相对于 “段” 为单位来操作的 @optional - (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type; // @optional - (NSString *)controller:(NSFetchedResultsController *)controller sectionIndexTitleForSectionName:(NSString *)sectionName ; //设置段的美国名字 //这个就是发送请求的方法 - (BOOL)performFetch:(NSError **)error; //这个属性,可见一个实例中的属性实体的排序方式,可以是几个不同的属性字段综合排序 @property (nonatomic, strong) NSArray *sortDescriptors; timeStamp
相关文章推荐
- js里面form传值
- Html5的多媒体元素:audio video
- Undefined symbols for architecture i386:和"_OBJC_CLASS_$_xx", referenced from:问题解决方法
- web 前端学习笔记
- CSS零基础入门
- 当前浏览器对HTML5支持状况(全平台)
- 当前浏览器对HTML5支持状况(全平台)
- Html5的列表元素:ol dl
- JavaScript在线文本编辑的实现
- CSS 之 光进入光
- Html5新增小元素:figure与figurecaption address progress meter mark details与summary
- Emacs Buffer workflow for Alfred2
- 关于AutoCompleteTextView实现前几个历史提示
- 使用CSS3来实现滚动视差效果的教程
- BufferedInputStream学习笔记
- 自定义jQValidate校验规则
- 最简单的HTML5游戏——贪吃蛇
- 前端多语言版本方案。
- OverFeat笔记
- iOS.ReactNative-4-react-native