Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a tab view programmatically with Cocoa/Objective-C

How do I create a tab view programmatically using Objective-C and Cocoa?

like image 452
Mike2012 Avatar asked Dec 17 '22 05:12

Mike2012


1 Answers

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]];
like image 107
Leibowitzn Avatar answered May 24 '23 19:05

Leibowitzn