Ramz
Ramz

Reputation: 596

how to use buttons from HomeView to select tabs from uitabcontroller

My Apps main view is having 5 buttons and I'm having tabbarcontroller with 5 tabs.So I need to select each tabs from each button action. Thanks in advance

Upvotes: 0

Views: 141

Answers (3)

Viktor Apoyan
Viktor Apoyan

Reputation: 10755

Use

self.tabBarController.selectedIndex = i; 

insted of i write the number of tab witch you wish !!!

Upvotes: 1

saadnib
saadnib

Reputation: 11145

assign tags to each button in view as 0,1,2,3,4 and use the same action for all buttons as

- (IBAction)selectTab:(id)sender 
{
    UIButton *button = (UIButton*)sender;

    [self.tabBarController setSelectedIndex:[button tag]]; 

    [self.tabBarController.view setNeedsDisplay]; 
}

Upvotes: 0

Anne
Anne

Reputation: 27073

Do something like this:

- (IBAction)selectSecondTab:(id)sender {
     self.tabBarController.selectedIndex = 1; 
    [self.tabBarController.view setNeedsDisplay]; 
}

Upvotes: 2

Related Questions