如何修复设置ManagedObjectContext错误?

时间:2014-08-10 20:37:25

标签: objective-c cocoa-touch

每当我运行我的应用程序时,它总是崩溃并给我这个错误:

  

2014-08-10 12:50:58.802 EIC Scanner [2184:133860] - [UITabBarController   setManagedObjectContext:]:发送到实例的无法识别的选择器   0x7ae7b9f0(lldb)

我有一个异常断点,所以它引导我进入这行代码:

rootView.managedObjectContext = self.managedObjectContext;

AppDelegate.h:

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;

@end

AppDelegate.m的一部分:

#import "AppDelegate.h"
#import "NotesList.h"
#import <CoreData/CoreData.h>

@implementation AppDelegate

@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // IMPORTANT: Pass the managedObjectContext to the root view controller
    NotesList *rootView = (NotesList *)_window.rootViewController;
    rootView.managedObjectContext = self.managedObjectContext;

return YES;
}

按要求NotesList.h:

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface NotesList : UIViewController <
UITableViewDelegate,
UISearchBarDelegate, UISearchDisplayDelegate
>

// CoreData properties  *******
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (strong, nonatomic) NSMutableArray *notesArray;

//UI VIEWS ***********
@property (retain, nonatomic) IBOutlet UIView *topView;

//TableView ********
@property (retain, nonatomic) IBOutlet UITableView *tableView;

@end

如果你知道如何解决这个问题,请评论如何解决。谢谢你的帮助!

0 个答案:

没有答案