Bobj-C
Bobj-C

Reputation: 5426

pressing a UITabBar button Programmatically in Xcode

i used the code below to make a UITabBarController :

inside AppDelegate.h:

    IBOutlet UITabBarController *rootController;
...
    @property (nonatomic, retain) IBOutlet UITabBarController *rootController;

inside AppDelegate.m

@synthesize rootController;

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self.window addSubview:rootController.view];
    [self.window makeKeyAndVisible];
    return YES;
}

Now i need to know how to implement this method inside AppDelegate:

- (void)SwitchToTab:(int)index{
    //go to tabview 1 or 2 ...
    }

Upvotes: 2

Views: 1155

Answers (1)

Caleb
Caleb

Reputation: 124997

You can do this:

self.rootController.selectedIndex = 2; // or whatever index you like

or this:

self.rootController.selectedViewController = oneOfTheViewControllersInTheTabController;

See the UITabBarController reference page for details.

Upvotes: 4

Related Questions