我的应用程序有一个嵌入式导航控制器。我想启动一个不是初始视图或rootViewController的特定viewController。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
UIViewController *rootController = (UIViewController *)self.window.rootViewController;
UIViewController *notificationController = [rootController.storyboard instantiateViewControllerWithIdentifier:@"NotificationsViewController"];
[rootController presentViewController:notificationController animated:NO completion:^{
}];
}
}
我知道我必须在这里输入代码,但我不确定我是如何编码的。有人可以帮忙吗?我收到错误代码:
Warning: Attempt to present <NotificationsViewController: 0x176883a0> on <SWRevealViewController: 0x17683750> whose view is not in the window hierarchy!
SWRevealViewController是我的侧边栏视图库。我的猜测是我的&#34; root&#34;不是我认为的。
如果我想将viewControllerX设置为我的根视图,我该如何实现?
答案 0 :(得分:0)
您应该首先初始化rootViewController。
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
YourViewControllerX * viewControllerX = [[YourViewControllerX alloc] init];
self.window.rootViewController = viewControllerX;
[self.window makeKeyAndVisible];
答案 1 :(得分:0)
试
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions{
[self.window addSubview:self.window.rootViewController.view];
[self.window makeKeyAndVisible];
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil){
...
}
}