从AppDelegate通过UISplitViewController呈现模态UIViewController

时间:2015-10-24 20:34:55

标签: objective-c uiviewcontroller

我已经编写了下面的代码,在UIViewController的{​​{1}}之上展示了一个模态UISplitViewController。但是,它不断抛出AppDelegate

Application tried to present modally an active controller <UISplitViewController: 0x138023800>.

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler { NSLog(@"%@", shortcutItem.type); if([shortcutItem.type isEqualToString:@"com.myapp.show-me"]){ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UISplitViewController *tc = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"]; self.window.rootViewController = tc; UINavigationController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"Navigation"]; UIViewController *detailViewController = [ivc.viewControllers objectAtIndex:0]; detailViewController.restaurant = @"1"; [tc presentViewController:detailViewController animated:YES completion:nil]; } else if([shortcutItem.type isEqualToString:@"com.myapp.see-all"]){ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UISplitViewController *tc = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"]; self.window.rootViewController = tc; } } 我做错了什么?

1 个答案:

答案 0 :(得分:0)

事实证明,我只需要提供UINavigationController而不是UIViewController

[tc presentViewController:ivc animated:YES completion:nil];