从远程通知打开视图时无法单击后退按钮
Cannot click back button when open view from remote notirication
我的 iOS 应用程序使用 Objective C。它收到一个远程通知,当用户点击它时,它会打开一个特定的视图。
此视图在导航选项卡中有一个后退按钮。在正常情况下可以回到根视图。但是,当我从通知中打开此视图时,无法返回任何视图或离开应用程序。
这是我的云杉代码:
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];
返回上一个视图的操作函数(在 viewClass.m 中):
- (IBAction)onBtnBackClicked:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
我认为问题在于,当我从通知中打开此视图时,没有父视图可以让它返回。任何人都可以帮助我,当用户从通知中打开此视图时,无论它是转到根视图还是返回到之前打开的应用程序
编辑:之前的回答没有考虑到您在 AppDelegate
中的事实。也许这个答案更好。
转动你的[self dismissViewControllerAnimated:YES completion:nil]
进入:
UINavigationController *navigationController = [[UINavigationController alloc] init];
UIViewController *yourPreviousVC = [[UIViewController alloc] init];
[navigationController pushViewController:yourPreviousVC animated:YES];
如果我错了或者我误解了问题,请随时纠正我的答案。
试试这个
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];
我找到了解决方案。我的应用程序有多个视图,我可以从导航列表中找到它们。当我想回到主视图时,我只是关闭当前视图。
目前,当我点击一个通知时会打开一个视图,我不能简单地关闭这个视图,因为它被认为是根视图。
我做了什么来解决它,我通过segue将我的视图(公告)连接到主视图,并设置一个标识符(例如:"leaveAnnouncementPage"。然后,在你的class中调用此功能在返回按钮的功能中返回到主视图:
[self performSegueWithIdentifier:@"leaveAnnouncementPage" sender:self];
这里还有一些有用的链接:
First
Second
谢谢大家的帮助,祝一切顺利
我的 iOS 应用程序使用 Objective C。它收到一个远程通知,当用户点击它时,它会打开一个特定的视图。
此视图在导航选项卡中有一个后退按钮。在正常情况下可以回到根视图。但是,当我从通知中打开此视图时,无法返回任何视图或离开应用程序。
这是我的云杉代码: 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];
返回上一个视图的操作函数(在 viewClass.m 中):
- (IBAction)onBtnBackClicked:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; }
我认为问题在于,当我从通知中打开此视图时,没有父视图可以让它返回。任何人都可以帮助我,当用户从通知中打开此视图时,无论它是转到根视图还是返回到之前打开的应用程序
编辑:之前的回答没有考虑到您在 AppDelegate
中的事实。也许这个答案更好。
转动你的[self dismissViewControllerAnimated:YES completion:nil]
进入:
UINavigationController *navigationController = [[UINavigationController alloc] init];
UIViewController *yourPreviousVC = [[UIViewController alloc] init];
[navigationController pushViewController:yourPreviousVC animated:YES];
如果我错了或者我误解了问题,请随时纠正我的答案。
试试这个
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];
我找到了解决方案。我的应用程序有多个视图,我可以从导航列表中找到它们。当我想回到主视图时,我只是关闭当前视图。
目前,当我点击一个通知时会打开一个视图,我不能简单地关闭这个视图,因为它被认为是根视图。
我做了什么来解决它,我通过segue将我的视图(公告)连接到主视图,并设置一个标识符(例如:"leaveAnnouncementPage"。然后,在你的class中调用此功能在返回按钮的功能中返回到主视图:
[self performSegueWithIdentifier:@"leaveAnnouncementPage" sender:self];
这里还有一些有用的链接:
First
Second
谢谢大家的帮助,祝一切顺利