I have 3 views in my application.
I would like to know how to properly open and load views when buttons are clicked.
Currently when a button is clicked from the first view I open the second view like this
[self dismissViewControllerAnimated:NO completion:nil];
getPLViewController = [[GetPLViewController alloc] initWithNibName:@"GetPLViewController" bundle:nil];
UIWindow* keyWindow= [[UIApplication sharedApplication] keyWindow];
[keyWindow addSubview:getProjectListViewController.view];
[self presentViewController:getPLViewController animated:NO completion:nil];
And now that the second view is open I open the third like this
currentPLViewController = [[CurrentPLViewController alloc] initWithNibName:@"CurrentPLViewController" bundle:nil];
UIWindow* keyWindow= [[UIApplication sharedApplication] keyWindow];
[keyWindow addSubview: currentPLViewController.view];
[self presentViewController:currentPLViewController animated:NO completion:nil];
I have no idea if this is correct anymore as I have been having trouble with the view showing up on its side if I try to load it before the previous view has finished loading or something along those lines.
This is how I go back from a viewcontroller
[self dismissViewControllerAnimated:NO completion:nil];
So I would like to know is this a correct way of doing it? or is there a better way?
any help would be appreciated.
Why you don't use a UINavigationController on your root view ?
You can hide the navigation bar and it will be cleaner and it will match with the Apple guidelines to push views.
Supposing you use XIB. When you add your first view from the
AppDelegate
, add anUINavigationController
and hide this one :Next on your
RootViewController
(first view) you add a button and push theSecondViewController
:The same in your
SecondViewController
to push the third one :and an action to back to the previous view :