popToRootViewControllerAnimated does not work with Tab Bar in iOS app - ios5

Application is structured as follows, this is a storyboard application using segue push
Navigation Controller (Root)
View Controller (Login)
Tab Bar Controller
Navigation Controller
View Controller (Options)**
**There is a logout button that executes
[self.navigationController popToRootViewControllerAnimated:NO];
This does nothing, trying to get to the Login view after pressing logout.
What is the correct approach?

Does self.navigationController have a value when you call popToRootViewController?
Add:
NSLog(#" self.navCon is %#", self.navigationController);
right before you call pop...

Related

How to present a login workflow? (modal and navigationController)

I currently need to present a login screen, followed by other screens before returning to the main menu.
Currently, I check if anyone is logged in on the main menu, and then present a modal login view (inside a UINavigationController) if not.
The user then fills in their login details and clicks submit. But before returning to the main menu (now logged in), I need to present two more screens to display some options.
I am not sure which structure to use for this. I thought about pushing the options screen onto the stack when the use clicks the submit button. However, Once they are done with that screen, and pop back to the root (login) view controller, is there any way to dismiss the modal view automatically, or should I structure this in another way?
Thanks.
You can push your login screen within a UINavigationController and use this controller to push your additional, post login screens.
// create and add your view controller to a navigation Controller
LoginController *loginController = [[LoginController alloc] init];
UINavigationController *navigationController = [UINavigationController alloc] initWithRootController:loginController];
// present it modally
[self presentViewController:navigationController animated:YES];
Once your user are done with the last of the post login screens, calling dismissViewController on the navigationController will go back to your main screens.
[self.navigationController dismissViewControllerAnimated:YES];
The best way to do so is to present it modally in your app delegate where you are using the navigation controller, just initialise your login view here and present it modally from your navigation controller like follows.
[self.navigationController presentModalViewController:loginView animated:yes];
and inside your loginview just use
[self.navigationController dismissViewController animated:YES];

How can i dismiss modalViewController without leaving current view?

My application is view based app. First view is login view. After login view i have MainMenuCcontroller which has a tabBarController:
#interface RunnoMainMenuController : UIViewController {
IBOutlet UITabBarController *tabBarController;
}
From login view controller, i am going to MainMenuController using this line of code:
[self presentModalViewController:mainMenu animated:YES];
this controller has 4 tabs. Now i need to do some stuff in viewWillAppear of a tabBarItem. viewWillAppear is not called when i tap a tabBarItem. I have a button in one of those tabBarItem's view which pops up a table view controller using presentModalViewController. This tableView uses dismissModalViewControllerAnimated:YES to disappear it. When i pop up this tableview and dismiss it then viewWillAppear of every tabBarItem works fine. If i will dismiss modalViewController in MainMenuController then it will again go back to login view. How can i dismiss modalViewController without leaving current view or any other solution? Thanks in advance.
You may need to consider how your views are presented. The tab bar controller should always be the window's root view controller. From the Apple docs:
When deploying a tab bar interface, you must install this view as the
root of your window. Unlike other view controllers, a tab bar
interface should never be installed as a child of another view
controller.
Rather than present your login view as the root view and the tab bar as a modal view controller, try it the other way round. The tab bar controller as root, with the login view as presented as a modal view controller from the view controller of whichever tab is shown initially. Dismissing this will then reveal the tab bar controller.

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.

back in navigationController

When I click the table row, go back to previous view without clicking back button.
I try
[self.navigationController dismissModalViewControllerAnimated:YES];
it's not working. How to dismiss pushViewController ?
dismissModalViewControllerAnimated is used to dismiss a Modal View Controller. These are the view controllers that slide up from the bottom of the screen. An example would be when you tap the button to compose a new email in the Mail app.
If you want the navigation controller to pop back to the previous view controller try using
[self.navigationController popViewControllerAnimated:YES];
Here's a link to the documentation for UINavigationController
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationController_Class/
[self.navigationController popViewController:YES]
With that line you are dismissing a modal view. That is not the same thing as popping controllers from the navigation controller stack.
You should instead do this:
[self.navigationController popViewControllerAnimated:YES];
This will pop the top controller.
Here is a link to the documentation.

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

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...

Categories