3

while integrating a payment gateway in my iOS app, I used rootViewController property as below:

 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];

It does the job, however now I have to press the back button multiple times to go back.

Why is it so?

4

1 回答 1

2

RootViewController 是应用程序堆栈上的第一个 ViewController。您应该只在方法上的 AppDelegate 中设置它:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

在您的情况下,由于您从 Storyboard 实例化它,因此将首先显示 ID 为“navCtrlID”的 NavigationController。如果它只有一个 ViewController,当你按下它时它不应该弹出导航堆栈。

如果您在添加此特定视图之前显示了 ViewController,则不应那样显示它。相反,使用例如:

[self presentViewController: controller animated:YES completion:nil];
于 2016-12-21T11:50:14.800 回答