我有一个基于核心数据的项目,其中有几个视图嵌入在导航控制器中。在其中一个视图中,我有一个打开模态视图的按钮。问题是我必须手动向视图添加UINavigationBar
。这意味着它使用我的表视图滚动。我已经认识到消除这个问题的方法是将视图嵌入到导航控制器中。当我尝试这个时,当我尝试打开模态视图时,应用程序崩溃并出现此错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setManagedObjectContext:]
我的applicationDidFinishLaunchingWithOptions
方法是通用核心数据应用的标准。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
UINavigationController *masterNavigationController= [splitViewController.viewControllers objectAtIndex:0];
GHiPadMasterViewController *controller = (GHiPadMasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
}
else {
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
GHMasterViewController *controller = (GHMasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
}
return YES;
}
如何将导航控制器用于模态视图?
我还应该注意到我正在使用故事板。