How to create navigation controller in a non-root controller view? - ios

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.

Related

Navigation Controller presented modally is empty 2nd time

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.

Unable to call navigation controller from present view controller in ios

In my application i am launching one screen using present UIModalViewController and on that screen I have oneUIButton, if we click on that UIButton alert will come then select yes on alert view now we have to call another view usingpushviewcontroller. But screen is not coming if we use below code can any one help me.
[self.navigationController pushViewController:requestViewController animated:YES];
Try with one root navigation controller and then present your controller modally as follows :
FirstViewController *firstView=[[FirstViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstView];
[self presentViewController:navigationController animated:YES completion:nil];
and then for push another view as follow :
SecondViewController *secondView=[[SecondViewController alloc]init];
[self.navigationController pushViewController:secondView animated:YES];
It will work first using present modal viewController and then using push navigation viewControllers on to the stack.

How to set root view controller of window to a UINavingationController when current root view controller of window is UITabBarController?

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

Navigation Stack in IOS7

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

IOS: start navigation controller form a secondary view

In my app I have a first view controller and I open my secondview controller in this way:
[self presentModalViewController:puntiVendita animated:YES];
but when I'm in secondViewController I have a tableView and I want to begin a navigation controller...what can I do to start a navigation controller from seconviewcontroller via code?
thanks
Just create a navigation controller:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:puntiVendita];
[self presentViewController:navigationController animated:YES completion:nil];

Resources