How to add UINavigationController to UITabBar app's first view? - iphone

This might not be exactly what you're thinking. I have a UITabBar app, with three tabs, all of which are linked to separate UIViews. On the first UIView (the default launch view) I have a search form. This view does not have a UINavigationController (as it's not wanted on this page).
When the user clicks search, I want to load a new view which has a UINavigationController (and still displays the Tab Bar at the bottom, with the first tab still highlighted).
From there, I want to just utilise the view as I normally would (which is out of the scope of this question so don't worry about that).
How would I go about doing this? I've seen some tutorials that suggest changing the class of the first view of the UITabBar from View Controller to Navigation Controller, but this adds the controller to the top of the first view (my search form) which isn't what I want :(.
Thanks in advance Stack Overflow!

Panic over - I have found a nice solution:
- (void) viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void) viewWillDisappear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}
This hides the UINavigationController on the first view.

Related

UINavigationBar unhides after search is made

I'm not sure how this works. I have a UITabBarController where my first tab is a UiNavigationController and its rootViewController has a UISearchDisplayController and UISearchBar. I set the rootViewController to be the UINavigationControllerDelegate.
I do this:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[self.navigationController.navigationBar setHidden:YES];
}
So my navigationBar will not show. That part works. After I make a search though and press enter, the navigation bar then comes in and pushes my search bar below it. What is happening here? Is there somewhere else I need to prevent the navigation bar from showing?
I know I could present my view controller modally instead since that is what I used to do. But there was no reason for it to be presented modally other than the navBar problem. Once the search is made and the user selects something to go to a more detailed view of the item, then I used to create a navigationController there. It seemed like it would flow better if I Just had one UINavigationController at the root since like I said, there is no reason to present the detailed list modally. Thanks!
Try replacing
[self.navigationController.navigationBar setHidden:YES];
with
[self.navigationController setNavigationBarHidden:YES animated:NO];

Pushing UIViewController to NavigationController does not actually push the view

I have this code in my table view controller (and delegate):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailStatus *detailViewController = [[DetailStatus alloc] initWithNibName:#"DetailStatus" bundle:nil status:[mStatuses objectAtIndex:indexPath.row]];
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
NSLog(#"exiting didselectrow");
}
And in my DetailStatus class:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil status:(NSDictionary *)pStatus {
NSLog(#"I am being called %d", [pStatus objectForKey:#"id"]);
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// some stuff
}
return self;
}
The funny thing is, my DetailStatus is actually being initialised, in the console window, it even outputs "I am being called 000001" but strangely the view is not being pushed to the table view...
I've checked the nib name, and it's ok. I checked the DetailStatus heading file, it looks ok (like this):
#interface DetailStatus : UIViewController {
So does anyone know why the view is not being pushed to the window even if I've initialised it and pushed it?
UPDATE: I tried logging some debugging messages to viewDidLoad in DetailStatus, and it seems like the view is not loaded even though the class was instantiated... I wonder why.
UPDATE2: I have a feeling that this might be my navigation controller organisation that's wrong.. I have this following:
Login page -> customtabbar -> First table view -> DetailStatus
-> Second table view -> DetailStatus
I think I'm only maintaining one navigation controller in that hierarchy. I've never created other navigation controllers. I only push view after another.
Thank you everyone for the answers! I will give out the bounty soon, I'll let other people vote first before the bounty expires.
After looking at it,the scenario seems to be same like me.What I faced for the first time when doing Tab+Navigation.
I am sure that there is some problem with your Tab+Navigation based application.
Although it shows the Tab as well as navigation are not able to navigate the basic flow.And it is very difficult to solve your problem with such less code.
Instead of this, I had an alternate solution for the same:
Once you have a tab bar in a XIB, the easiest way to approach this is to drag a UINavigationController object over from the Library window (looks like a left nav bar button on a gold background) into the Tree View for your tab bar (the text only view, not the GUI). Place it under the tab bar, then drag your existing view controller under the tab bar controller instead of under the tab bar.
When you go to view that tab you should then see a navigation bar on the top of it... if you are loading the navigation controller from another xib, you'll modify the nav bar in the tab bar xib.
else you can below you can follow the best url for the same:
http://books.google.co.in/books?id=2yYlm_2ktFYC&pg=PA179&lpg=PA179&dq=navigation+with+the+tab+based+application+iphoneSDK&source=bl&ots=nf2YYjX5Am&sig=COpHj9wOtsDChQBglpsljSTsElw&hl=en&ei=3ZoFTeGSOI_tsgbc_Iz6CQ&sa=X&oi=book_result&ct=result&resnum=6&ved=0CDAQ6AEwBQ#v=onepage&q&f=false
http://www.youtube.com/watch?v=LBnPfAtswgw
Hope this will surely solve your problem.
Unless the UINavigationController is the immediate parent of your table view controller, [self navigationController] will return nil.
I'm unclear exactly where it lies in the view controller hierarchy, based on your explanation, but I suspect you might have your UITabBarController nested within the navigation controller, when it should be the other way around. If, by chance, you actually mean to push the tab bar off screen (and thus you do want the tab bar controller nested within the navigation controller), you will need to call something like the following:
UIViewController *parentViewController = self.parentViewController;
[parentViewController.navigationController
pushViewController:detailViewController
animated:YES
];
P.S. Once the push is working correctly, you won't need to deselect the tapped row, as UITableViewController does this automatically when the view reappears.
I not seen putting status on the end of the init of the view. Guessing that's something you added.
Dont you just need to do [self pushViewController etc instead of the navigationController bit
Could it be that the nib is not wired up correctly. I.e. In the nib there is no connection between the view and the controller so even though the controller is pushed correctly, the navigation controller cannot find the view.
Just a guess!
You need to implement like above In tab controller put navigation controller according to your tabs and in navigation controller you can put your tab item.And also you need to set tab bar item nib file.then on tapping a tab you get tab screen and because of navigation controller you can easily navigate.even you can navigate on the screen of any tab main screen.
This is the way which you need to implement.
It definitely helps you but you need some logical implementation.
Is your tableViewController directly pushed to the navigation controller or is there another viewController in between ? Check the value of [self navigationController] against the value of your navigationController (from the place your actually instanciate it)
Once check that have you initialized the First Tableview and Second TableView with Navigation controller or not.
While adding to the tabBar, have you added the UINavigationController or only the UIViewController object.
PM_FirstNavigationController *First_navController = [[PM_FirstNavigationController alloc] initWithRootViewController:FirstTableViewController];
tabBarController.viewControllers= [NSArray arrayWithObject: First_navController];
You have to add the view controllers to the tabBar's like that.
Then while calling the [self navigationController], it will give navigation controller object.
Regards,
Satya

how to work without with navigation controller

hi before i never use navigation controller,
can i use navigation controller like this
consider in my app there is three view (ie main view, first view, second view)
on main view, two UIButton's with button action to move into first view and second view respectively
and to go back to main view, i have to place navigation controller(like back button wiht title) on first view and second view(note:- not navigation controller on main view)
i want to place navigation controller on first view and second view for back to main view
note:- on my main view no navigation controller, navigation controller will be on first and second view used as back buttons and title
can you guide me to the solve this problem
#nandakishore i suggest you to choose the navigation based app in the beginning because you need navigation controller in most of your views(first view and second view)
And you hide the navigation controller when main view didLoad and unhide that when view will dissappear
eg:- In mainview.m
- (void)viewDidLoad {
[super viewDidLoad];
[[self navigationController] setNavigationBarHidden:YES animated:NO];
}
and
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[self navigationController] setNavigationBarHidden:NO animated:NO];
}
now by doing this u will not get navigation controller in mainview but get that in other two views
Hope this may help u....Good luck!!!

UINavigationController - do not want this to appear first page iPhone

I am going to use an UINavigationController to keep track of all the views the user visits. This is all well and good except that I do not want the navigation bar to appear on the first view. Is it possible not to show the navigation bar on the first view?
Thanks!
sure, you can use - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated on the navigation controller, when you want to hide it and then use it again to display it.
so if you are on a view controller that is the root for the UINavigationController, you might want to call it in the viewWillAppear: method:
[self.navigationController setNavigationBarHidden:YES animated:NO];

How does the search display controller hide the navigation bar?

When you enter the search bar handled by a search display controller, it slides the view up and pushes the navigation bar up with it. This is easy enough to do, however, when you click a search result and a new view is pushed on the navigation controller's stack, the navigation bar slides in from the right with the view!
How is this done? If you simply set the navigation bar to hidden or shown, it happens instantly. I can't figure out how it seems to be hidden just for one view controller in the stack!
Many thanks,
Michael
You can animate the transition of the navigation bar. See -setNavigationBarHidden:animated: for more details.
If you need to do this on a per-view controller basis, just override the view controller's -viewDidAppear: and -viewWillDisappear: methods, e.g.:
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
The above will hide the navigation bar when this view controller is pushed on top of the navigation stack, and show the navigation bar when the view controller is popped off.
You can call -setNavigationBarHidden:animated: whenever you want, but those two methods are useful for applying lots of UI changes.
-(void)viewDidLayoutSubviews{
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
it will not hide navigation bar.