UITabBar and UINavigationController - iphone

Let me make the question more clear.
I have tab bar application with navigation controller included in each tab.
When click the tab 2 i go to login screen. From login screen i navigate to next screen (say screen 2) using login button. When i am on screen 2 if i cilck the tab 2 i again go to login screen. I do not want this. I want application to remain at same screen even if tab 2 is clicked again.
If i cilck any other tab in between then it works as expected.
How to achieve this??

- (BOOL)tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController {
if ([tabBarController.selectedViewController isEqual:viewController])
return NO;
}
return YES;
}
Alternatively, you can catch taps on the tab bar and check if the selectedIndex changed or not.

The UITabBarController will pop to the root view controller if you tap a tab that you are currently displaying. To prevent this behavior take a look at this question:
Disable action - user taps on tabbar item to go to root view controller

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.

How to display Navigation bar when tab bar item clicked

I m working on Iphone application which is having UITabBarController and UINavigationController
I am switching to UIWebView in flow of the project before which its all Native
When I switch to webview I am able to hide the Navigation bar
but when I clicked on a tab which brings it to home page I cant see navigation bar unless I select any option and go to next view
I did find out abt tabbar function
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
but I m not getting how to unhide or display the navigation bar again??
Please help
I guess you use
self.navigationController.navigationBarHidden = YES;
to set the navigationController's navigationBar to hidden.
If you use this in the other views in viewWillAppear you need to set it to non hidden again
self.navigationController.navigationBarHidden = NO;

Home View in UITabBarController

I have a starter UIView and if user clicks the button in starter view present a tabbar model view. In that view, I have a tab bar controller with 4 items as the first one "Home" tabbar item where if user clicks it dismisses the tabbar controller view and go back to the start view (so when tabbar view is loaded it starts with the second tabbar item). My question is: how can I dismiss the tabbar controller when user clicks the home tabbar item.
Ehm I think this is against guidelines and would advice you to try a different approach. However, you could make the home button load a view which class has [self presentModalViewController:starterViewController animated:NO]; in viewWillAppear

How do you make the "more" button of a UITabBarController return to the root view

I have a UITabBarController which has been created programatically. There are 6 tabs within the tab bar which has forced a more button to appear, which is great and works beautifully!
Whilst testing the app, one of the testers raised a point. When they select the more button, then select one of the options in the more menu, the resulting view is presented as expected. If they then select another tab from the tab bar and subsequently return to the more tab the view that they previously selected is still visible!
So, my question is this. How can I make the "more" button return to the table menu when it is selected? I have tried the obvious, as it is appears to be a subclass of UINavigationController I tried popping to root etc but to no avail... The iPod app does exactly what I want to do so I know its possible, just wondering if there is something I am missing?
Any help is appreciated
Graham Whitehouse
Try this delegate method:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if ([tabBarController selectedIndex] > 3) {
[viewController.navigationController popToRootViewControllerAnimated:NO];
}
}

iPhone TabBar selection cancelling

I am developing an iPhone app that displays several views, all acessed via Tab Bar items. However I need to add an additional item to the Tab Bar that simply launches a URL in Safari.
I've accomplished this by adding an empty placeholder view to the TabBar and returning FALSE from shouldSelectViewController when the this view's tabBarItem is clicked on, and launching Safari at the same time.
That code is:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if([[viewController tabBarItem] title] == "Website"){
//... launch Safari
return FALSE;
} else {
return TRUE;
}
}
PROBLEM: If the TabBar has too many items, and this "Safari Launch" tab is pushed off to the "More" navigation controller, I lose the capability to intercept the event and prevent the view from loading when clicked.
Any suggested tips?
You might consider having that tab simply display a UIWebView with the web site.
I second glorifiedHacker in that having a tab bar item quit the application and launch another is not expected behavior.
My idea is, if you do not allow the users to customize the tab bar items, "Safari Launch" being pushed to "More" will never happen. You can prevent editing by setting the customizableViewControllers of your tab bar to nil or an empty array.