我有一個項目,其中包括一個組合tabbarController和導航控制器。 對不起,becauce我不能發佈圖片,圖像,這裏的鏈接:CoreData UINavigationController managedObjectContext錯誤
http://s12.postimage.org/58lbzzxm5/Screen_Shot_2012_11_10_at_9_56_07_AM.png
代碼NAppDelegate.h:
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
@interface NAppDelegate : 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
代碼NAppDelegate.m:
#import "NAppDelegate.h"
#import "TVC_TabProvince.h"
@implementation NAppDelegate
@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
NSArray *arrController = [tabBarController viewControllers];
TVC_TabProvince *controller = (TVC_TabProvince*) [arrController objectAtIndex:0];
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
在添加導航控制器之前,它運行沒有任何問題。但是,當我添加此,錯誤出現:
error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
[UINavigationController setManagedObjectContext:]: unrecognized selector sent to
instance 0x74b26b0'
非常感謝你! –