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?
The RootViewController is the first ViewController on the Application Stack. You should only set it in your AppDelegate on the method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
In your case, since you instantiate it from Storyboard, the NavigationController with ID "navCtrlID" will be displayed first. If it only has one ViewController, when you press back it shouldn't pop the navigation stack.
If you have ViewControllers presented before adding this particular view you shouldn't show it like that. Instead, use for example:
[self presentViewController: controller animated:YES completion:nil];