4

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?

SiHa
  • 7,830
  • 13
  • 34
  • 43
ios_Dev
  • 95
  • 1
  • 10
  • 2
    Could you clarify you question please. What is happening when you press the back button multiple times? –  Dec 21 '16 at 11:38
  • when i press back button, it shows me a blank screen, on clicking back again, it looks like it is going back, after a few attempts it goes to the previous controller. – ios_Dev Dec 21 '16 at 11:40

1 Answers1

2

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];
LopesFigueiredo
  • 146
  • 1
  • 8