在我的 iOS 应用程序中集成支付网关时,我使用了 rootViewController
属性如下:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *controller = [storyboard instantiateViewControllerWithIdentifier:@"navCtrlID"];
[[UIApplication sharedApplication].keyWindow setRootViewController:controller];
[self.navigationController presentViewController:controller animated:YES completion:nil];
它完成了这项工作,但是现在我必须多次按下后退按钮才能返回。
为什么会这样?
最佳答案
RootViewController 是应用程序堆栈上的第一个 ViewController。
您应该只在方法上的 AppDelegate 中设置它:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
在您的情况下,由于您从 Storyboard 实例化它,因此将首先显示 ID 为“navCtrlID”的 NavigationController。如果它只有一个 ViewController,当你按下它时它不应该弹出导航堆栈。
如果您在添加此特定 View 之前显示了 ViewController,则不应那样显示它。相反,使用例如:
[self presentViewController: controller animated:YES completion:nil];
关于ios - 什么是 rootViewController 以及何时使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41261893/