views:

431

answers:

2

I need to create a tab view programatically using objective C and cocoa but I can't find any good resources showing how to do this. Can anyone suggest something?

A: 

I would take a look at the source code for the transmission bit torrent client. Look at the preferences window or the info window.

Matthieu Cormier
A: 

This adds a tab view to a window:

   NSTabView *tabView = [[[NSTabView alloc]
      initWithFrame:NSMakeRect(10,10,300,300)] autorelease];
   [[window contentView] addSubview:tabView];

This adds a tab to the tab view:

   NSTabViewItem *item = [[[NSTabViewItem alloc]
      initWithIdentifier:@"tab1"] autorelease];
   [item setLabel:@"Tab 1"];
   [tabView addTabViewItem:item];

At this point you'll want to add some controls to the tab. You should definitely do this with interface builder. Create a nib with a view, make the file owner a NSViewController. Then do the following:

   NSViewController *viewController = [[[NSViewController alloc]
      initWithNibName:@"myView" bundle:nil] autorelease];
   [item setView:[viewController view]];
Leibowitzn
Thank for your comments I'll try this. As far as your final comment goes I cannot use the interface builder because I am trying to build this tab view as a widget that can be used with a version of lisp that uses an objective c bridge. I am not just trying to build an app that has a tab view which is why I was asking about how to do all this programatically.
Mike2012
You should still be able to use NSViewController. In fact, you can probably assemble the tab view (and its subviews) in IB and use NSViewController to load that.
Peter Hosey