iPhone How to dismiss a UITabBarController and then show it again? - iphone

I will try to explain myself as best as possible, I know the title does not say much. Basically i have 4 Navigation Controllers embedded in Tab Bar Controller.
What I want to do is have one of this Navigation Controllers push a new Navigation Controller embeded in aTab Bar Controller dismissing the original Tab Bar Controller. When the user clicks the back Button on the Navigation Controller the original Tab Bar Controller is called.
I tried simply pushing the new Tab Bar Controller in the Navigation Controller, but of course i get now 2 tab bars in my view. At the moment what I am doing is having the navigation controller present my new Tab Bar Controller as a modal View and it works Ok. But I do not have the back button in the Navigation Controller so at the moment I just dismiss my Modal View, which I guess is kinda the same.
I have this in code:
myTabBarController = [[UITabBarController alloc] init];
myTabBarController.viewControllers = [NSArray arrayWithObjects:myNewsNavController, mostPopularController, myAboutNavController, nil];
Where myNewsNavController is Navigation Controller containing a View Controller linked to a TableView then when the user tabs the accesoryButton it presents the modal Controller at the moment.
But I think the user experience would be better if there was a back button instead.
So how can I dismiss the Tab Controller? and then when dismissing the modal view have it back again?. Any help will be Greatly appreciated. Thank you.
-Oscar

I'm not sure exactly what you want, but have you tried setting
myViewController.hidesBottomBarWhenPushed = YES
?

MYViewController *controller = ...;
controller.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:controller animated:YES];
You have to set hidesBottomBarWhenPushed = YES on the controller you are going to push into the view...

Related

navigation controller doesn't show up iphone

I have an application with a tab bar as the root controller. I have four items in the tabbar. The second item is a table view and this should have a navigation controller of course, the thing is that i don't even get the navigation bar to show up and i have no idea how to do it. So i tried to guess after a long time in google without success. This is what i did in the viewDidLoad method:
SearchNavController *navController = [[SearchNavController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:navController];
[searchNavController release];
With that i got an IlegalArgumentException.
How can i get the navigation bar to show up?
Thanks in advance guys
Have a nice day!
Since you used interface builder to setup your tabbarcontroller. follow the following steps to get navigation bar and navigation controller in your tabbarcontroller:
Open Mainwindow.xib and select tababarcontroller .
In the attribute inspector , select the item1 in viewcontroller and from the arrows to the right change it to navigation controller.
Try this link:
link 1
Your navController should probably an ordinary UIViewController with the view you want to display. Also you need the following to actually display the navigationController:
[self presentModalViewController:navigationController animated:YES];
The navigation controller should now show up with your view as it's content.
IF you are using interface builder. Then Add UINavigation controller in each tab bar then add your view controller in uinavigation conrtroller. If you have 4 tabs then you have to put 4 navigation controller.
UITabbarcontroller ->>Tab Bar >>
UINavigationController >> set its class to your viewcontroller

problem with tab bar, not displaying the tab bar upon navigating to that page

In my test project I have some 5 tabs on click of a tab it will go to that corresponding class, on click of back in that screen I will come back to my home page but with out the tab bar.. earlier what 5 tabs were there those are not coming ...
following code I am using under back button
where DataEntry is the class to where i need to navigate
- (void) back_Clicked:(id)sender
{
DataEntry *avController;
UINavigationController *addNavigationController;
if(avController == nil)
avController = [[DataEntry alloc] initWithTabBar];
if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];
[self. navigationController presentModalViewController:addNavigationController animated:YES];
}
is I have to add that navigation controller to the tab view? how can I get the tab bar on click of back can any one help me ,thanx in advance
As I understand this, you must already be pushing this view controller either via navigation controller or modally. So the idea would be to simply dismiss it right?
If you have used [self.navigationController pushViewController:animated:] then just do [self.navigationController popViewControllerAnimated:YES]; . This should take you back to the earlier view controller.
If you have presented this modally like you have done here, you should do [self.navigationController dismissModalViewControllerAnimated:YES];.
If you need to return back from a view to the previous view using a back button inside a tab view , i would recommend using a navigation controller inside the view for each tab where you require this functionality. Trying to implement a custom back button without using the navigation controller, in my opinion, is only making things tough for yourself.
If you only want one view to be displayed when you tap on a tab bar button then an ordinary view controller inside the tab bar view should suffice.
The tab bar shouldnt be disappearing altogether unless its been implemented incorrectly.

Designing an Application with different ViewControllers

after reading a lot of tutorials and threads here on stackoverflow there is one basic question left in my head.
The structure of my App should be the following:
MainMenu - fullscreen without a navigation bar but 2 buttons (button1 and button2)
Page1 - should appear by pressing button1 and should have a navigation bar at the top with a "back"-button to get back to the MainMenu.
Page2 - should appear by pressing button2 without a navigation bar at the top. Page2 should be a UISplitView. There must be a back button somewhere.
(I think this is where the problem starts, a UISplitView can't be presented modally, can it?)
You should be able to add subpages to Page1.
So how can I do that? I don't need executable code but just a hint on how the structure of my app should be. For example where to add the navigation controller, how the MainMenu looks like.
Thanks in advance!
Are you trying to create an Application for iPad?
Your Application's UI sems inconsistent being First View the only view without navigation Bar.
You will be using standard navigation to navigate to page1 from home page. So you will be adding a navigation Controller with Home View Controller as a Root View COntroller with hidden navigation bar.
eg.
-(void)applicationDidFinishLaunching:...
{
HomeViewController * hvc = [[HomeViewController alloc]init];
UInavigationController * nvc = [[UINavigationController alloc]initWithRootViewController:hvc];
nvc.navigationBar.hidden = YES;
[window addSubView:nvc.view];
}
Then on tap of first Button you will be pushing the Page1 View Controller
-(IBActtion)button1Pressed:(id)sender
{
Page1ViewCOntroller * p1vc = [[Page1ViewCOntroller alloc]init];
[self.navigationController pushViewCOntroller:p1vc animated:YES];
}
In viewWillAppear: method of Page1ViewController unhide the NavigationBar and hide it in the viewWillDisappear: method
Your Page 2 needs to be splitViewController.
Now about Split View, Apple says
The split view controller’s view should always be installed as the root view of your application window. You should never present a split view inside of a navigation or tab bar interface.
But as there is no "must" written in the above statement, and since its finally a View Controller in itselt, you should be able to add it on the window or another view.
Try to create a VIewController, with split VIew added on it, and like page1, push the View on the navigation Controller.

tabBarController navigation problem/question

I have a simple tabBarController application where the user can navigate around 3 views.
In one of the views I have a UIButton that when touched moves the user to a fourth view. the problem is that the new view doesn't have the tab bar navigation visible.
what do I need to do to the fourth view to have it also use the tabBarController feature set.
thanks for any help
here's the code that transitions to the fourth view when a UIButton is touched:
-(IBAction) nextQuestion {
Question2 *q2 = [[Question2 alloc] initWithNibName:#"Question2" bundle:nil];
q2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:q2 animated:YES];
[q2 release];
}
A modal view controller always takes up the entire screen. Its purpose is to provide a modal interface that does not let the user interact with other parts of the UI until they dismiss the modal view.
To display another view inside a tab, you could make the root controller of that tab a navigation controller. A button tap would then push the Question 2 controller on the nav controller's stack.

adding navigation effect to view based application?

I have created View based application, here i need to navigate between views when button pressed.
so in first view controller i have created action for button pressed.
-(IBAction)loadSecondView:(id)sender
{
SecondView *sView = [[SecondView alloc]initWithNibName:#"SecondView" bundle:nil];
[self.navigationController pushViewController:sView animated:YES];
[sView release];
}
this code is not working, anything i am missing,
i can do this by [self.view addSubview:sView]; but i need navigation effect.
Thanks in advance.
You can't just hook a UIView instance to a navigation controller, that's not how they work.
Take a look at the "Navigation-based Application" template in Xcode, to learn how navigation controllers work.
You can use view controllers while hiding the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:NO];
You can then map UIButton instances to selectors that push or pop view controllers, while keeping the navigation bar hidden.
These button instances are subviews of the view controller's view property.
Hiding the navigation bar can help provide the illusion that you are not using a navigation controller, while giving you all the functionality of the navigation controller.
Alex is right, if you create just a "View Based Application" project, no UINavigationController was created so when you push something on it nothing happen, that's normal.
You have to create a UINavigationController and make you main view its rootViewController, then you can push on it a new viewController.
I have got a solution for this,
In View based application the appdelegate file creates object for, view controller and added that view to main window, to do our task, delete the controller in mainwindow.xib and add a UINavigation controller,and create a object to it, and connect outlet to it,and then add this navigation controller view as a sub view,
its work fine.