我在 Master-Detail-Application 上创建了一个新的 iPhone 项目。因为我之前需要登录,所以我在情节提要中添加了一个新的 ViewController,选中“是初始视图控制器”并将新创建的类 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到底是从哪里来的。我从来没有创建或添加一个??