我是iOS新手,难以实现拆分视图主细节控制器。我创建了一个新项目
现在,故事情节如下图所示
http://i40.tinypic.com/2e1ccg9.png
我知道并阅读了一些较旧的帖子和Apple人机界面指南,Split View应该是根视图控制器,但我也看过像Tripadvisor和Yelp这样的应用程序!已实施相同的,并已获得Apple批准。
我能够让它在没有核心数据的情况下工作,但是当我用coredata模板启动项目时,似乎工作正常。当我运行程序时,它显示以下错误:
2013-07-11 04:54: 44.207 Trial4 [21421:c07] - [UISplitViewController topViewController]:无法识别的选择器发送到实例0x8424990 2013-07-11 04:54:44.211 Trial4 [21421:c07] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [UISplitViewController topViewController]:无法识别的选择器发送到实例0x8424990' * 第一次抛出调用堆栈: (0x1fa7012 0x13e4e7e 0x20324bd 0x1f96bbc 0x1f9694e 0x2643 0x16157 0x16747 0x1794b 0x28cb5 0x29beb 0x1b698 0x1f02df9 0x1f02ad0 0x1f1cbf5 0x1f1c962 0x1f4dbb6 0x1f4cf44 0x1f4ce1b 0x1717a 0x18ffc 0x24ad 0x23d5) libc ++ abi.dylib:terminate调用抛出异常 (LLDB)
所以我假设问题是我必须在AppDelegate.m中实现一些代码。有人可以帮助我解决需要在
中实现的代码- (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[0];
MasterViewController *controller = (MasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
} else {
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
}
return YES;
}
有人可以让我知道如何实现相同的(修改上面的代码),如果我需要添加一个额外的主视图控制器,我该怎么办?
由于
我通过修改以下代码让应用程序的iphone部分工作; 任何可以提供修改ipad代码建议的人:
- (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[0];
MasterViewController *controller = (MasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
} else {
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = tabBarcontroller.viewControllers[0];
MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
}
return YES;
}
这里附有一些我想要实现的照片:
横向模式下iPad中Yelp的屏幕截图: http://i40.tinypic.com/11uf1af.png