Re: Dynamic Typing
Re: Dynamic Typing
- Subject: Re: Dynamic Typing
- From: Ondra Cada <email@hidden>
- Date: Thu, 28 Mar 2002 20:10:05 +0100
On Thursday, March 28, 2002, at 05:37 , Victor Soriano wrote:
I'm writing an application whose interface is defined in IB. It's
organized
as follows:
A primary class exists which defines outlets for most of the controls in
the
window.
The window contains a tab view where a custom class has been defined to
handle the outlets on each page of the tab view. These "tab view classes"
have been instantiated and the outlets from each page of the tab view
connected to it's corresponding class.
I understand this "each tab view has its own controller, instantiated in
NIB, of a special class".
The primary class contains an id variable which I would like to
dynamically
cast as one of the tab view classes each time the corresponding tab view
page is selected.
You don't need to cast anything. Just use the outlet.
The question is: without specifically defining static outlets in the
primary
class, how to I get access to the tab view class instances that are
created
when the nib is loaded?
Actually the problem is not in dynamic typing, but in gaining an access to
the controllers, right?
Well, since there is nothing like "TabViewItem's represented object" which
you could set in IB, you need some trick. There are many of them possible,
including some handy, but very dirty ones. Wait if somebody other would
not advice a better solution; if not, I would do that programmatically:
@interface MyTabViewController:NSObject {
IBOutlet NSTabViewItem *theControlledItem; // to be linked in NIB to
the appropriate tab view item
IBOutlet MyMainController *mainController; // -"- to the main
controller, which keeps track of those special controllers
}
...
@implementation MyTabViewController
-(void)awakeFromNib {
[mainController addTabViewController:self forItem:theControlledItem];
}
@end
In short time I don't see a better solution (but splitting the NIB into
more separately loaded ones, which I probably would do myself), but I bet
there is, just I've overlooked it.
I currently have a scheme that dynamically creates the instances as I need
them, but I realized that additional instances are already being created
when the nib is loaded. I need to either use the instances created by the
nib, or dealloc them and use my existing scheme.
In this case I guess the best way is to create instances (of those tab
view controllers, I presume) programmatically, and use them in NIBs as
appropriate File's Owners. If so, of course you don't need the trick above
(nor any other one).
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.