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.
Related
I have made a custom tab bar in my application ...On clicking the same tab bar button again the view adds ...Please tell me how to manage the view so that if a view is on window and if i presses the tab bar again the view shouldnt be added or loaded again.
Check whether viewcontroller is nil or not. if viewcontroller is nil then add new one else simpally popToRootViewController. You can find many tab bar implementation, Please refer below link
https://github.com/boctor/idev-recipes/tree/master/TabBarAnimation
https://github.com/iosdeveloper/InfiniTabBar
https://github.com/i300/TweetBotTabBar
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
I have a iPad application where i am using more than one Views. The thing is i want to display the TabbarController page while clicking on Button that is on main page. I am able to call the TabBarController directly from delegate method like adding TabBarController to MainWindow in Inspect window. But the thing is i am asking for users to first login to application and after successful loging, Dashboard appears where i have Buttons. Clicking on button i am displaying Tableview in one Tab bar and in another Tabbar Add to list form.
Thanks in advance,
Sam
What I can get from your post is that you want to have the user log in before the Tab Bar appears with your views.
If that's the case, then you want to set your login view as the main view of the window, and then after they log in set the view to be the view of the Tab Bar.
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];
}
}
I'm developing an iPhone application that have a TabBarController with two tabs.
Each tab contains a UIWebView that loads a web page from my web site.
I want to add a view that will function as a welcome screen that doesn't show the TabBarController itself (full screen view) and indicates that the application is being loaded.
After that I want to hide the welcome screen and show the TabBarController
Can anyone point me to the right direction on how to implement this functionality?
Thanks!
I would suggest using a modal view controller for the loading view:
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
If you present the modal view controller as soon as your app launches (with no animation), it will be on top of everything, including the tab bar, even if it was presented by one of the tab view controllers.
Once the loading is done, you can dismiss the modal view controller:
- (void)dismissModalViewControllerAnimated:(BOOL)animated
You could animate the dismissal or not.
If your Default.png (launch screenshot) looks like the modal view, the whole thing should be pretty seamless.