更改Master-Detail-Application的初始View Controller

时间:2013-02-11 23:28:22

标签: ios storyboard viewcontroller launch master-detail

我在Master-Detail-Application上创建了一个新的iPhone项目。由于我之前需要登录,我在 storyboard添加了一个新的ViewController ,勾选了“是初始View Controller ”并分配了新创建的类LoginViewController 到这个ViewController。

此外但不相关(在我看来),我创建了一个segue并将其从ViewController连接到NavigationController(Master-Detail-Template)。

AppDelegate.m 已更改为在启动时启动新控制器:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    /* // Old Master-Detail-View-Controller
    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
    MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
    controller.managedObjectContext = self.managedObjectContext;
     */

    (LoginViewController *)self.window.rootViewController;

    return YES;
}

这将最终出现错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '-[UICollectionViewController loadView] loaded the "Qn5-Rj-iPA-view-IRE-eP
-ILZ" nib but didn't get a UICollectionView.'

我也试过这个:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    LoginViewController *loginViewController = [[LoginViewController alloc] init];

    self.window.rootViewController = loginViewController;   //Set the view controller
    [self.window makeKeyAndVisible];

    return YES;
}

导致类似的错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'UICollectionView must be initialized with a non-nil layout parameter'

我的错误在哪里?

我没有得到的是,错误消息中的 UICollectionView 来自哪里。我从来没有创建过一个或添加一个??

Storyboard

2 个答案:

答案 0 :(得分:5)

我的LoginViewController错误地从UICollectionViewController而不是UIViewController继承。我修复了它,它的工作原理。

这解释了我首先没有理解的奇怪的错误消息。一如既往真相在源代码。重新检查有帮助。

答案 1 :(得分:0)

您无需在AppDelegate中加载视图控制器。只要您的stroyboard是在项目设置中加载的那个,它就应该自动加载。