0

我有一个基于核心数据的项目,在导航控制器中嵌入了几个视图。在其中一个视图上,我有一个打开模式视图的按钮。问题是我必须手动将 a 添加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;
}

我如何将导航控制器用于模态视图?

我还应该注意我正在使用情节提要。

4

0 回答 0