简体   繁体   中英

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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM