NSSegmentedControl selecting NSTabView

I discovered, quite by accident the other day, that it is possible to use an NSSegmentedControl to control which Tab of an NSTabView is displayed. Here is how to do it.

First of all, it is much easier to change the selected tab if you leave the tabs on to begin with. So, I would suggest building all of the NSTabView’s tabs first. I’ve done five, each with a different control.

View1.png View2.png

Now, you can alter the NSTabView so it doesn’t show the Tabs:

View1Tabless.png TabViewInspector.png

You can now add the NSSegmentedControl, and style it as you wish. I really like the Small Square styling.

SmallSquareNSTabView.png

Now to hook up the connection. There is an outlet on NSTabView called takeSelectedTabViewFromSender:, which can be hooked up to an NSSegmentedControl.

Connection.png

You will need to ensure that your initially selected cell and view are the same index, which prohibits having it save the value between runs (or you might be able to, if you know more than me).