objective-cmacoscocoansbuttonnstabview

How to make a button change a tab in Objective C Cocoa applications


In this tutorial, I learned how to make a button say hello world in an OSX Cocoa application with Objective C, using XCode 7.

Now how do I make it call my tab view and make it switch a tab programmatically?

See, I'm implementing my interface with hidden tabs and when one clicks a button, it changes the tab. This is for an installer application I'm coding.


Solution

  • Create an outlet in the AppDelegate and connect it to the tabview.

    Create an action in the AppDelegate and connect the button to this action. Example (tabView is the outlet):

    - (IBAction)selectMiddleTabViewItem:(id)sender {
        [self.tabView selectTabViewItemAtIndex:1];
    }