How to push uiviewcontroller over tabbarcontroller - iphone

I have a tabbar app. each tab has uinavigationcontroller. but all navigationcontroller's Shows Navigation Bar value is NO.
i control the which navgation control is active in
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
event in AppDelegate. Then i the user taps a row in a table in a tab i call the same method (openDetail)in appdelegate. i want to push DetailViewController full screen, not in tabs controller. i tried some ways but never worked. so i push it as a modalview.
[currentNavController presentModalViewController:detailVC animated:YES];
how can it come/go from right side.
i just want it to work like normal rootviewcontroller. but new controller should come over tabbarcontroller like USA Today app.

present the view controller like this
[tabBarController presentModalViewController:detailVC animated:YES];

Related

popToRootViewController with animation and then switch tab

I have a UITabBarController with 4 views/tabs. Each view is a UINavigationController.
How can I popToRootViewController on one of these UINavigationControllers then switch tabs and push a viewController onto another UINavigationController using animation throughout?
So the sequence would be:
At start we are in Tab 1's view which is a UINavigationController. A View has been pushed onto it beyond its root ViewController.
-Tab 1
- UINavigationController1
- RootViewController1
- SomeViewController1 [We are here]
-Tab 2
- UINavigationController2
- RootViewController2
A button is tapped in SomeViewController1 that causes the following:
UINavigationController1 pops to its root view controller (with animation)
UITabBarController switches tab to Tab2
SomeViewController2 is pushed onto UINavigationController2 (with animation)
So the view looks like this:
-Tab 1
- UINavigationController1
- RootViewController1
-Tab 2
- UINavigationController2
- RootViewController2
- SomeViewController2 [We are here]
int tabYouWantToSelect=2;
BOOL isNavigation=YES;
[[self.tabBarController selectedViewController].navigationController popToRootViewControllerAnimated:YES];
//if any controller is presented as a model view then
//[[self.tabBarController selectedViewController] dismissModalViewControllerAnimated:YES];
[self.tabBarController setSelectedIndex:tabYouWantToSelect];
//the newly pushed view controller's viewWillAppear
-(void)viewWillAppear:(BOOL)animated {
if(isNavigation){
[self.navigationController pushViewController:objAddLocation animated:YES];
}
}
Pop to rootview controller on the navigation controller you are currently showing in your UITabBar Controller
Change the tab programmatically
Push the viewController on the new tab's navigationController programmatically
All this should happen through your applications delegate implementation file.
If you need the code as well let me know...
Here is how I've done it. I feel it is much cleaner than infecting the root VC with code that isn't relevant to it.
I created a UINaviationControllerDelegate that checks the number of UIViewControllers left on its UINavigationController. If there is only one left it posts a stackAtRoot notification. Meanwhile just before I popToRootViewController I register a Command that is triggered by this notification. When it is triggered I have it orchestrate the tab switch and pushing of a VC onto the new tab's UINavigationController. It immediately unregisters the command, so it will not be called again unless reregistered.

TableView in NavigationBar and Tabbar Switch Between Tabs Gets Bad Access

I'm building an app that combines tabbar and navigation bar. In one of tabs, I have a UIButton and by touching it, I push a Tableview into stack of navigationcontroller. Then, without returning to the root view controller manually by pressing Back buttons I change to another tab from tabbar and when I come back to the tab with the tableview inside, I get bad access error.
I've already tried popping the tableview from navigation controllers stack, or not releasing the tableview but I could't make it.
Thanks...
Assuming you've created your tabBar and Navigation Controllers in the AppDelegate, you can code your app to return each tab to the root view when it is selected.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (viewController == firstViewNavigationController) {
[firstViewNavigationController popToRootViewControllerAnimated:NO];
} else if (viewController == secondViewNavigationController) {
[secondViewNavigationController popToRootViewControllerAnimated:NO];
}
}
I am using this and it is working fine in my app. I am releasing my Navigation Controllers in the dealloc method. I have also made my AppDelegate conform to the UITabBarDelegate protocol.

Puzzle about TabViewController?

I have made an app in which i have 2 tabs.and there are navigation controller in them,
The issue is that once i click on the tab bar and there is navigation bar and the view changes as i drill down.But when i go to the second tab and then come back to the 1st tab then it opens the view which was there previously when i changed the tab.So it retain the view whereas i want that that tab should start up with the same first initial view.
From where we can do this by info.plist or what..>?
Thanks in advance ...
Adopt UITabBarControllerDelegate protocol and implement tabBarController:shouldSelectViewController: method.
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)controller {
[(UINavigationController *)controller popToRootViewControllerAnimated:NO];
return YES;
}
This assumes that all tabs have navigation controllers.
That's not how tab view controllers work. You can implement this method in your app delegate (after making it the delegate for the UITabeBarController)....
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
Then call a reset method (or similar) on your view controller to pop back to the root view controller.
This is not how you normally work with UITabBarControllers however....
You can implement
- tabBarController:didSelectViewController:
in the delegate of the UITabBarController and then call
– popToRootViewControllerAnimated:
on the UINavigationController

Double Clicking on UITabBarControllers Tab goes to root of Navigation controller

I have a UITabBarController setup with 2 UINavigationControllers.
One UINavigationController has One UIViewController, the other UINavigationController has Two UIViewControllers. If you then navigate to the second UIViewController and click the Tab that is already selected it bring you to the root of the UINavigationController (This would be the first UIViewController).
Is there a way to stop this from happening? I do not want the user to be able to click an already selected Tab to go to the root of the Navigation Controller.
To do this you need to implement a function in your app delegate to pick up the tabbar delegate calls.
In your app delegate.m file, in the didfinishlaunching method, add this line
[tabBarController setDelegate:self];
then implement this method (also in your app delegate):
- (BOOL)tabBarController:(UITabBarController *)theTabBarController shouldSelectViewController:(UIViewController *)viewController
{
return (theTabBarController.selectedViewController != viewController);
}
This gets called as part of the tab delegate protocol and will stop the selection of a tab if its already the selected one.
Hope that helps.

How are people popping their UINavigationController stacks under a UITabBarController?

I have four UINavigationControllers assigned each to a tab in a UITabBarController. Each UINavigationController manages a UIViewController, which may itself branch out into other UIViewControllers below it hierarchally.
My question is, in a case in which a user, under one tab, has navigated to a UIViewController that hierarchally BELOW the main UIViewController managed by the UINavigationController, and then the user pushes a different tab, and then goes back to the original tab, HOW can I make it so that the user is presented with the main UIViewController managed by the UINavigation controller? and not the page where he left off?
UITabBarController is set up in IB
Implement the UITabBarControllerDelegate protocol and pop to the root controller whenever your delegate is notified that the user has selected a different tab.
Something like:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[viewController.navigationController popToRootViewControllerAnimated:YES];
}
The code above should pop to the root controller of any navigation controller that is the main view controller of the newly selected tab. You could try implementing the protocol in your application delegate. And do not forget to actually assign the app delegate as the tab bar controller's delegate.
didn't work for me originally, then later on I noticed that all my viecontrollers for different tabs are actually UINavigationControllers
and thus I modified the above code a little bit as follows and it worked:
[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];