4

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?

Roman
  • 3,799
  • 4
  • 30
  • 41
dunnmifflsys
  • 613
  • 2
  • 9
  • 21
  • The error is obvious, the compiler tells you what it is. `NSTabView` has no priperty called `tabBarController`. What are you trying to do? –  Jun 14 '13 at 06:10
  • I said what I was trying to do, change the tab view when a button was clicked. I found the base idea from [here](http://stackoverflow.com/questions/5413538/switching-to-a-tabbar-tab-view-programmatically?rq=1). Again, I'm terrible at Objective-C, so I'm not sure what I'm doing. – dunnmifflsys Jun 14 '13 at 06:28
  • Huh? That's for iOS... Instead of making assumptions, you should read the documentation... –  Jun 14 '13 at 06:28

1 Answers1

13

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.