Re: Need help with dynamically adding tabs/populating from nib
Re: Need help with dynamically adding tabs/populating from nib
- Subject: Re: Need help with dynamically adding tabs/populating from nib
- From: Todd Ransom <email@hidden>
- Date: Thu, 16 Jun 2005 19:44:11 -0600
OdyExerciseView *newExercise = [[OdyExerciseView alloc] init];
//exerciseArray is an array in the windowController
[exerciseArray addObject:newExercise];
[NSBundle loadNibNamed:@"OdyTabView" owner:newExercise];
[newTabItem setView:newExercise];
Is newExercise an NSView subclass or a controller? You are setting it
as File's Owner and trying to set it as the view for the tab item,
which doesn't make sense to me.
What I did in my app was create a "view controller" with an outlet to
an NSView that contains the view I want to display. So the above
would look more like this:
OdyExerciseViewController *newExerciseController =
[[OdyExerciseView alloc] init];
//exerciseArray is an array in the windowController
[exerciseArray addObject: newExerciseController];
[NSBundle loadNibNamed:@"OdyTabView" owner: newExerciseController];
[newTabItem setView: [newExerciseController mainView] ];
Todd Ransom
Return Self Software
http://returnself.com
On Jun 16, 2005, at 11:59 AM, Jeffrey Johnson wrote:
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
_______________________________________________
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