I have a tabBarController with 4 tabs. In the fist one I need to show an UINavigationController which has a UIView in it. When the user presses a button inside that view I need to display another UINavigationController in tab 1 replacing the old one. Is this possible?
I tried using this code with no luck
UINavigationController *tableNavController = [[UINavigationController alloc] initWithNibName:#"Nav2" bundle:nil];
[[self.tabBarController selectedViewController] setView:tableNavController.view];
This replaces the view but not the controller.
Please help.
Thanks in advance.
Why not just push a fresh viewController onto tab 1's navigationController?
Related
I have a MainMenu which navigates me to a TabBarController with 4 views (4 Tabs) in it.
Now I've a button in the 4th view of the TabBarController which OnClick should take me to the MainMenu.
Problem is when I pushViewController (MainMenu) I'm not able to dismiss the TabBarController and also NavigationBar is not visible on the MainMenu!!
Can someone please suggest me how to solve this, Thanks in advance.
Do not use this :
[self.navigationController pushViewController:mainMenuViewController animated:YES];
Try using this:
[self.navigationController popViewController Animated:YES];
Take the reference of your same MainMenu and then push to that view controller
[self.parentViewController.navigationController popViewController animated:YES];
UITabBarController is a container controller and you're adding viewControllers into it like so:
NavController
||
TabBarController
||
DisplayingViewController
since displayingViewController doesn't have a navigationController associated with it but the TabBarController does, you need to call for its parentViewController.
I'm coding an iphone app and I've an issue on how to manage views presentation. Indeed, when user starts the app a "home" View shows up containing a search form. When user presses a "search" button I want a method to open a navcontroller that displays the search results. I made another view containing a TableView with the purpose of serving as "results" View. I want the "results" view to allow user to go back to the "home" view (the search form) but I don't want the "home" view to have a navigation controller bar...
Any idea on how to solve this ?
Thx in advance,
Stephane
The easier way is just to hide the navigation bar on the 'home' view and show it back on the other view...
You have to create a UINavigation controller manually and present it modally as follows:
MapViewController *mapViewController = [[[MapViewController alloc] init] autorelease];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mapViewController];
[self presentModalViewController:navController animated:YES];
I have been trying to create a navigation bar back button.
Here is my code :-
UIBarButtonItem *barButton = [[[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:nil]autorelease];
self.navigationItem.rightBarButtonItem = barButton;
But it isn't displaying anything on navigation bar.
I am using UIViewController, not an UINavigationController.
Is UINavigationController is the only way to achieve this?
Any help would be really appreciated.
Any link to a good tutorial will be great.
Thanks.
Without the viewcontroller having a navigation controller (i.e viewController.navigationController != nil) you cannot add it in this manner.
One thing you can do is if it is being created by the nib is to just drag a bar button item into a navigation bar and link it via IBAction.
I'd recommend pushing this view controller out of a nvigationcontroller - you will get all those things for free:
UIViewController *vc = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navCntrl1 = [[UINavigationController alloc] initWithRootViewController:vc];
If you have your view controller being created from a NIB file in Interface Builder, and the view controller's design surface has a navigation bar on it, the easiest way to do this would be to drag a bar button item from the objects inspector right onto the navigation bar's right side. You would then create an IBAction in your header and implementation that you would hook up to.
I achieve this inserting the button directly in the UINavigationBar:
[yourUINavBar insertSubview:yourButton atIndex:1];
UIViewController's -navigationItem method does only work together with UINavigationController or other UIViewController containments.
You will have to get access to the UINavigationBar and set the item directly.
If you want to have a navigation bar, and have it work as you expect, create a UINavigationController using your UIViewController as the root view controller. Use that UINavigationController where you are using your UIViewController now.
Check out UINavigationController at developer.apple.com for more details.
I created a UInavigation controller in my xib file. The UINavigation controller is the top level control. I don't need a parent view. Later on I will manually add the UINavigation controller to the window.
What is the best way to instantiate the UINavigationController? I can't seem to figure out how to do this.
If you do not need to do anything special in the .xib file it is way easier to do this programmatically by adding the following code to your app delegate:
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:myView]; //myView is a view you previously created
[self.window addSubview:nav.view];
In my application which is based on a tabbar view controller with many uinavigationviewcontrollers for each tabbar items, I want to present at some point (at application launch) with a call to presentModalViewController that contains a uinavigationcontroller as a root so the user can do a few things... when he or she is finished, the Done button at the top right corner can be tapped to dismiss the modal view controller and then return to the base tabbar view.... How can I do that with Interface Builder ?
In XCode, create a new View XIB file and open it in Interface Builder. In this xib file, delete the View and drag a UINavigationController into it's place.
Then, in your view controller code, something like
UINavigationController *controller = [[UINavigationController alloc] initWithNibName:#"ModalViewController" bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];
Will load your XIB and present it.
Hope this helps, any other questions don't hesitate to comment on this answer!
S