[英]How do I navigate complex view hierarchy based on remote notification in iOS?
[英]How do you change the initial view controller in an ios application based on a remote notification?
我有一个正在实现远程通知的应用程序。 我的愿望是根据以下三个条件之一来更改初始视图控制器:用户自行启动应用程序(无通知); 或者,用户收到了可疑的活动警报; 或者,用户收到了犯罪警报。 我已经在appDelegate中实现了应用程序didReceiveRemoteNotification:方法。 基于通知和用户对通知的响应,我实现了以下代码:
UITabBarController *tbContr = (UITabBarController*) self.window.rootViewController;
UINavigationController *navContr = [tbContr.viewControllers][2];
ViewCrimesController *viewCrimes = [navContr.storyboard instantiateViewControllerWithIdentifier:@"ViewCrimes"];
[navContr presentViewController:viewCrimes animated:YES completion:nil];
[self.window.makeKeyAndVisible];
我遇到的问题是导航控件-即返回按钮和导航栏标题; 呈现时不在ViewCrimesController上。 我试图以多种不同方式加载ViewCrimesController。 无论哪种方式,我都会收到错误提示说没有segue(此视图是映射视图的模型视图),或者我试图在活动视图上加载该视图,或者再次没有导航控件。
我是否需要对导航控件进行专门编程,还是在尝试加载视图时缺少某些东西?
我在其他文章中看到了有关动态更改初始视图的参考。 但是我还没有看到任何指示需要添加控件的特定编程的东西。 您能提供的任何帮助将不胜感激!
苏珊
您是否看过帖子, 使用情节提要以编程方式设置初始视图控制器
该帖子的答案可能会解决您的问题,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *viewController = // determine the initial view controller here and instantiate it with [storyboard instantiateViewControllerWithIdentifier:<storyboard id>];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
您还可以下载此样本,然后根据需要实施它。
只需更改键窗口的rootViewController,示例代码放在此处,希望对您有所帮助:
UIStoryboard *storyboard = self.window.rootViewController.storyboard;
UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"rootNavigationController"];
self.window.rootViewController = rootViewController;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.