If I present a controller with a view controller, is it part of the self.navigationcontroller stack?
In essence:
UBSLoginViewController* loginView = [[UBSLoginViewController alloc] initWithNibName:LOGINVIEW bundle:nil];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:loginView];
navigation.navigationBarHidden = YES;
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
[loginView presentViewController:[[UBSLoadingViewController alloc] initWithNibName:LOADINGVIEW bundle:nil] animated:YES completion:nil];
Is the loading view part of the navigation stack? Essentially, I want to present a modal view that will not be part of the root navigation stack.
If I present a controller with a view controller, is it part of the
self.navigationcontroller stack?
No.
You need to push the view controller onto your UINavigationController in order for it to be on the navigation controller's stack. Right now you are modally presenting on a view controller which is an entirely different concept.
Pushing onto a navigation controller looks something like this.
[self.navigationController pushViewController:loadingViewController animated:YES];
Related
I am trying to present a UITableViewController modally on one of my view controllers which is further embedded in a UITabBarController. The code I am using is -
ContactTableViewController *contactsVC=[self.storyboard instantiateViewControllerWithIdentifier:#"contact"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:contactsVC];
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
contactsVC.myDelegate = self;
[self.navigationController presentViewController:navController animated:YES completion:nil];
The view is presented just fine the first time I do it but when I navigate to this view again in my app, the view being presented is completely blank.. No navigation bar buttons, no title, nothing..
Can't figure out a reason... Any help is very much appreciated!
UPDATE:
HomeViewController *vc = [[HomeViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
This what I do to navigate to that view again while unhiding the tab bar. Home View is the view that presents the Contacts Table View modally.
I have a UITabBarController which contains four navigation controllers.
When user taps a button , I want to set the root viewController of window to a new navigation controller.
How do I do that in Objective-C?
Using a modal view controller will look better than simply replacing the root view controller, and should produce the same effect as you are looking for. Basically, you create an instance of your view controller, add it to a new navigation controller, and then present the navigation controller modally:
- (void)buttonPressed
{
MyViewController *vc = [[MyViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:nav animated:YES completion:nil];
}
I am trying to push a view controller to a navigation controller, but nothing happens.
I have the following code in my appDelegate (which works fine it seems):
ViewController1* VC1 = [[ViewController1 alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:VC1];
self.window.rootViewController = navController;
And the following code in VC1:
ViewController2 *VC2 = [[ViewController2 alloc]init];
[self.navigationController pushViewController:VC2 animated:YES];
VC2 gets initialised but isn't pushed to the navigation controller and therefor never presented. I have tried looking for answers for a while now but without success. What am I missing?
Thanks in advance!
Turns out the problem was that another navigation controller was active and had to be dismissed. The code posted was correct and all but I had totally missed another navigation controller.
I am creating a UINavigationBar using the following,
UINavigationController *navigationController = [[UINavigationController alloc] init];
[view addSubview: navigationController.view];
How come it shows up like this?
(source: gyazo.com)
I want it to be on the top of the view but there is space there, why?
Thanks.
You are not creating things correctly. You should create your view controller, then create a navigation controller, passing the view controller as the nav controller's root controller. Then you make the nav controller the app's root controller.
UIViewController *vc = ... // create your view controller
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
window.rootViewController = nc;
The code you posted does not create a nav bar, it creates an entire navigation controller.
Put this code to ViewWillAppear
- (void)viewWillAppear {
UINavigationController *navigationController = [[UINavigationController alloc] init];
[view addSubview: navigationController.view];
}
Also you should resize nav controller to self controller bouns
My application setup is like this:
I have a navigation controller (create in the app delegate)
View 1 --Push--->View2---Push--->View3 ---Modal transit (slide up) --->View4 --->Push-->View5
What I want to do is to create a new navigation controller in View4 so that I can push to another view from view5
I didn't have experience of creating navigation controller in view other than root view controller.
Can someone give me some guide or instructions for how to implement it?
Here is how I did it.
+ (UIViewController *)viewControllerWithNavigation
{
id controller = [[**YOUR VIEW CONTROLLER** alloc] initWithNibName:**FOO** bundle:**BAR**];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
[controller release];
return [navController autorelease];
}
I present this view over the root view controller using:
UIViewController *controller = [**YOUR VIEW CONTROLLER** viewControllerWithNavigation];
[self.window.rootViewController presentViewController:controller animated:YES completion:NULL];
You, of course, can present t over any view you want
select view4 in your storyboard, and select the menu Editor -> Embeded In -> Navigation Controller. good luck.