我的iOS应用程序使用Objective。它收到一个远程通知,当用户单击它时,它将打开一个特定的视图。
此视图在导航选项卡中有一个后退按钮。在正常情况下,可以返回根视图。但是,当我从通知中打开此视图时,不能返回到任何视图,也不能离开应用程序。
下面是我的云杉代码: 1.从AppDelegate.m打开一个特定的视图:
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewAnnouncement =[storyboard instantiateViewControllerWithIdentifier:@"Announcement"];
self.window.rootViewController = viewAnnouncement;
[self.window makeKeyAndVisible];我相信问题是,当我从通知打开这个视图时,没有父视图让它返回。当用户从通知中打开此视图时,有人能帮我吗?无论它是转到根视图还是返回到以前的打开应用程序。
发布于 2017-09-27 15:00:05
我找到了解决办法。我的应用程序有多个视图,我可以从导航列表中找到。当我想回到主视图时,我只是忽略了当前的观点。
很好地,当我单击通知时会打开一个视图,我不能简单地拒绝这个视图,因为它被认为是根视图。
为了解决这个问题,我通过segue将视图(公告)连接到主视图,并设置了一个标识符(例如:"leaveAnnouncementPage“)。然后,在您的类中,只需在back按钮的函数中调用这个函数,返回到主视图:
[self performSegueWithIdentifier:@"leaveAnnouncementPage" sender:self];这里还有一些有用的链接:
谢谢你们的帮助,一切顺利
发布于 2017-09-26 10:34:11
编辑:前面的答案没有考虑到你在AppDelegate中的事实。也许这个答案更好。
转动你的[self dismissViewControllerAnimated:YES completion:nil]
转入:
UINavigationController *navigationController = [[UINavigationController alloc] init];
UIViewController *yourPreviousVC = [[UIViewController alloc] init];
[navigationController pushViewController:yourPreviousVC animated:YES];如果我错了,或者如果我没有回答这个问题,请毫不犹豫地纠正我的回答。
发布于 2017-09-26 13:46:18
尝尝这个
Announcement *annouce = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Announcement"];
HomeVC *home = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"HomeVC"];
[((UINavigationController *)self.window.rootViewController) setViewControllers:@[home,annouce] animated:YES];如果应用程序已经打开,并且您想要转到前一页
Announcement *annouce = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Announcement"];
UIViewController *visibleView = ((UINavigationController *)window.rootViewController).visibleViewController;
[((UINavigationController *)self.window.rootViewController) setViewControllers:@[visibleView,annouce] animated:YES];https://stackoverflow.com/questions/46423586
复制相似问题