Dismiss modal view and change tab in Xcode - iphone

I am looking for a way to dismiss a modal view and switch to a specific tab on the tab bar.
I think I need to combine....
self.tabBarController.selectedIndex = 3;
and
self.dismissModalViewControllerAnimated:YES;
Both work individually but not when combined.

How about setting the tab bar's selected index upon the calling of viewDidDisappear or viewWillDisappear for the dismissed controller? This way, they won't be called together but will happen one after the other

Related

Tab Bar Controller disappears

I'm currently working on an iOS app in Xcode.
I have a few View Controllers that are part of a tab bar controller. I also have another view controller, that I access with a push from a button on one of the tabs (modal segue). I also have a back button on this extra view which is also a segue that leads back to the view controller where we came from.
However, when I press this back button, and come back on the view controller that was part of the tab controller, the tab bar at the bottom is no longer displayed.
Why is this happening and how can I solve this?
Try this, this will help you
- (void)viewWillDisappear:(BOOL)animated
{
self.hidesBottomBarWhenPushed = NO;
}
Try adding ViewController.hidesBottomBarWhenPushed = NO; when you are popping back to the viewcontroller.

setting a tab bar controller view controller programmatically

Is there a way to set the view controller on the tab bar controller programmatically? Lets say I want it to show the second's tab view controller programmatically, is there a way to do that?
This is useful if I logout from my app, which is done from my third tab, when the user logins it should start from the 1st tab again. When I logout I am just showing a present modal view controller on top of what the previous view is, so I somehow needs to reset it again to the first tab bar without re-initializing it all over again.
The issue is now how do I do this?
From Apple's documentation it looks to me like you could just call the following two functions:
[myTabBarController setSelectedIndex:0];
[myTabBarController setSelectedViewController:[myTabBarController.viewControllers objectAtIndex:0]];
Hi ye you can do this
You might have tabbarcontroller object in appDelegate.
So on logout button
make object on your appDelegateClass and do this:-
appDelegate.tabBarController.selectedIndex=0;
Have a look at the reference on UITabBarController. Work with selectedIndex and selectedViewController.

iPhone pop navigation controller when tab bar selected

I have an iPhone app with a tab bar and in the first tab there is a UINavigationController. How can I force the navigation controller to popToRoot when selecting the tab? The default behaviour does this the second time you select it but I wish to do it on the first one.
Thanks
One way to do this would be to use UITabBarControllerDelegate’s –tabBarController:didSelectViewController: method to be notified when the user selects the navigation controller. Then, in that method, pop your navigation controller as desired.

How can I change to a different view within a different navigation controller than I'm in at the moment

I have a tab bar controller and a navigation controller. Each tab bar item has its own navigation controller and a few views within those.
I want to programitically switch to another view in a another navigation controller and have the correct corresponding tab bar item selected.
Is this possible, if so can you show me how ?
Heres some typical lines I'm using at the moment within the same navigation controllers.
[delegate.settingsNavController pushViewController:nextController animated:YES];
[delegate.reportNavController pushViewController:nextController animated:YES];
When ever I try this, nothing happens, I stay in the current view, however if I were to tap another navigation button and the view I'd tried (with code) wasn't normally the first view, that view would show first.
So it is changing the view within the navigation controller, but its not showing it.
You also have to switch to the new tab:
self.navigationController.tabBarController.selectedIndex = settingsTabIndex;
[delegate.settingsNavController pushViewController:nextController animated:YES];

Tab bar navigation

I have made an application in which I have four tab bars. I have used the below code to go to the second view in a button's click method. It goes to the second view but the second view is not showing with tab bars. How can I fix this?
- (IBAction)Existinguser:(id)sender
{
ExistingUserViewController *existingUserViewController =
[[ExistingUserViewController alloc]
initWithNibName:#"ExistingUserViewController" bundle:nil];
[self presentModalViewController:existingUserViewController animated:YES];
[existingUserViewController release];
}
Presenting a view controller modally will show that view controller above all ther other UI elements (this includes the navigation bar and tab bar, but not the status bar).
If you want to show your "second view" as the view on the second tab, then you need to set the view controller you want to use as the second tab's view controller. That way when you press the second tab, the second view controller will be shown, and the second tab will be selected and visible.
I might be mistaken, but do you have a single tab bar with four tabs and you are looking for a way to change to the second tab? You can do this with the following code:
self.tabBarController.selectedIndex = 1;
btw the code you attached to your question is displaying a new model view controller above the current view controller. This is the reason no tabbar is shown.
If you are trying to create a navigation based app using tabbar, in IB, change the tab's viewcontroller to UINavigationController. You can then use the UINavController methods to navigate between views. In case you don't want to show the navbar, just set that property in IB.
Here's a good example of how you can use tab bar with navbar