fetchedResultsController返回nil

时间:2015-03-12 14:32:51

标签: objective-c core-data nsmanagedobjectcontext

我正在使用Core Data作为在GeoFencing项目中保存数据的方法。我有应用程序的GeoFencing部分正常工作。我在保存我正在检索的MKMapItem个对象时遇到了问题。

长话短说,当我做一个segue 我返回managedObjectContext 的值,但 nil fetchedResultsController我很难过为什么。

这是我的设置

搜索商品:一旦用户在地图上找到要保存的内容,他们就会从ResultsTVC转到AddPointOfInterestVC

AddPointOfInterestVC打开MKMapItem并显示姓名,地址等。此部分有效。我遇到麻烦的地方是将其插入managedObjectContext的{​​{1}}。

在从AddPointOfInterestVCprepareForSegue的{​​{1}}中,我设置了ResultsTVCAddPointOfInterestVC,因此我可以点击managedObjectContext中的按钮使用fetchedResultsController添加带有备注和类别的AddPointOfInterestVC

MKMapItem

我的insertNewObject

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UIButton*)sender { if ([[segue identifier] isEqualToString:@"addPOISegue"]) { AddPOIViewController *destinationVC = segue.destinationViewController; // point added here so the button "knows" which index it's referring to CGPoint point = [sender convertPoint:CGPointZero toView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point]; NSLog(@"NSIndexPath *indexPath's index is %@", indexPath); MKMapItem *item = _mapItems[indexPath.row]; NSLog(@"ResultsTVC item is %@", item); destinationVC.item = item; // Core Data segue setup // Pass the MOC to destinationVC AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; destinationVC.managedObjectContext = appDelegate.managedObjectContext; // Pass the FRC to destinationVC destinationVC.fetchedResultsController = appDelegate.fetchedResultsController; } 档案:

AddPointOfInterestVC

.h档案

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "MapViewController.h"

// Core Data Properties
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;

我返回.m的值,但 - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"AddPOIVC item is %@", self.item); NSLog(@"AddPOIVC managedObjectContext is %@", self.managedObjectContext); NSLog(@"AddPOIVC fetchedResultsController is %@", self.fetchedResultsController); } 的值为nil。我很难过为什么。

在这个项目之前,我使用过“密码”,因此在MasterVC / DetailVC之外插入/移出MOC对我来说有点麻烦。任何想法都将不胜感激。

0 个答案:

没有答案
相关问题