Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Tab Bar Programmatically

I'm trying to change the tab view when a button is clicked. I have this code:

- (IBAction)startScratch:(id)sender {
     _mainTabBar.tabBarController.selectedIndex = 1;
        //Error: ^ Property tabBarController not found on type "NSTabView*"
}

The .h file has these lines of code:

@property (weak) IBOutlet NSTabView *mainTabBar;
- (IBAction)startScratch:(id)sender;

I'm assuming I should replace _mainTabBar with something, but if so, what?

like image 981
dunnmifflsys Avatar asked Sep 01 '25 16:09

dunnmifflsys


1 Answers

As @H2CO3 mentioned, there is no tabBarController property in NSTabView. If you read the documentation, you’ll notice that NSTabView provides a few selection methods, including -selectTabViewItemAtIndex:, which you can use like so:

- (IBAction)startScratch:(id)sender {
    [_mainTabBar selectTabViewItemAtIndex:1];
}

Note that the first tab is at index 0.