How do I create a tab view programmatically using Objective-C and Cocoa?
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]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With