Search code examples
iosios7uitabbarcontrolleruitabbar

iOS tab bar item leading to Twitter


I have a tab bar navigation view and I would like to use one of the tab bar items to go to a twitter link either in the twitter app or safari. When you go back to the app, I would like it to be in the same view as before the tab bar item was touched.

I'm not sure if this is possible as I am new to iOS.


Solution

  • You may consider just directly opening the twitter link when the user selects the tab, but not actually changing tabs. Just override the tabBarController:shouldSelectViewController: delegate method and do something like this:

    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
        NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
        if(index == yourTwitterTabIndex){
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"whatever the Twitter app url is"]];
            return NO;
        }
        return YES;
    }