Need help with dynamically adding tabs/populating from nib
Need help with dynamically adding tabs/populating from nib
- Subject: Need help with dynamically adding tabs/populating from nib
- From: Jeffrey Johnson <email@hidden>
- Date: Thu, 16 Jun 2005 13:59:00 -0400
Hello,
I'm working on a product whose UI consists of a single window containing a tabbed view. The first tab will contain a table (NSTableView) of items, acting as a table of contents. As line items in the table of contents are clicked, new tabs are added to the tab view. The tab content consists of several nested RBSplitViews of text views, table views, and an NSOpenGLView.
(The customer requires the UI to be laid out this way- multiple tabs in a single window. Changing the UI to multi-window isn't an option for me, and yes, I know I'm going to have to change this tabView to "tabless" and write my own "tab proxy" drawing view to handle the case of lots of tabs.)
I made a simple window and prototyped the collection of views I need for the tab contained in a container view (OdyExerciseView) and got it working in a window. Then I dragged the OdyExerciseView to a new windowless nib file (OdyTabView.nib), with the OdyExerciseView set as the File's Owner.
For the moment, i simplified the table of contents to a single button ("add tab"), whose action is the following in the tab window's window controller:
- (IBAction)newTab:(id)sender
{
NSTabViewItem *newTabItem = [[ NSTabViewItem alloc] init];
[newTabItem setLabel:
[NSString stringWithFormat:@"Exercise %d",[tabView numberOfTabViewItems] +1]];
[[self tabView] addTabViewItem:newTabItem];
OdyExerciseView *newExercise = [[OdyExerciseView alloc] init];
//exerciseArray is an array in the windowController
[exerciseArray addObject:newExercise];
[NSBundle loadNibNamed:@"OdyTabView" owner:newExercise];
[newTabItem setView:newExercise];
[newExercise release];
[[self tabView] selectTabViewItem:newTabItem];
[[self tabView] setNeedsDisplay:YES];
[newTabItem release];
}
The result is that new tab(s) with the label "Exercise <N>" are created and made the current tab each time the table of contents button is pressed, but none of the subviews appear in the new tab. I'm pretty sure that the nib is being read and loaded correctly, because the IBOutlets in the newExercise OdyExerciseView get populated and breakpoints/NSLogs I have in the -awakeFromNib on OdyExerciseView fire. (In fact, the awakeFromNib in OdyExerciseView gets called twice during loadNibNamed:. Why?)
I'm a relative newbie to Cocoa, so I'm hoping there's something basic I've left out trying to load and display tab content subviews dynamically, like some "orderFront" selector or something. One thing I haven't done is anything with the FirstResponder placeholder in the OdyTabView nib, because I'm not sure exactly what role this plays in a "sub" nib file.
I've Googled/poked around the various Cocoa archives, but no one seems to have a complete example how to make multiple tabs from a template nib, just "do this.. do this.. try this" advice in English, without stringing together the actual Cocoa APIs. Help!
Thanks
Jeffrey Johnson
Macintosh Development
Wavefunction, Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden