简体   繁体   English

pushViewController后,后退按钮不起作用

[英]Back button doesn't work after pushViewController

This is how I am pushing a UIViewController : 这就是我推送UIViewController

[tabController setSelectedIndex:0];
UINavigationController *navController = [tabController selectedViewController];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
NotificationViewController *notificationController = (NotificationViewController*)[mainStoryboard
 instantiateViewControllerWithIdentifier: @"NotificationViewController"];
[navController pushViewController:notificationController animated:YES];
navController.navigationBarHidden = NO;  

When NotificationViewController is visible and I tap Back button, nothing happens. NotificationViewController可见并且我点击“后退”按钮时,什么也没有发生。 The previous UIViewController had a gesture in UINavigationBar but I have removed it in the UIViewController 's viewWillDisappear . 先前的UIViewControllerUINavigationBar具有手势,但是我已在UIViewControllerviewWillDisappear中将其删除。 But still the NotificationViewController 's Back button doesn't work. 但是NotificationViewController的 “后退”按钮仍然无法使用。

You probably call the pushViewController before the view is visible. 您可能在视图可见之前调用pushViewController

Make sure you don't call your pushViewController in the viewDidLoad . 确保不要在viewDidLoad调用pushViewController

Your pushViewController should be used only after viewDidAppear is called if you want your navigation controller to work properly with the back button. 如果您希望导航控制器与后退按钮一起正常工作,则应仅在调用viewDidAppear之后使用pushViewController Otherwise, the navigation controller will add the title to the previous view controller without the redirection link. 否则,导航控制器会将标题添加到没有重定向链接的前一个视图控制器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM