Re: Dynamic Typing
Re: Dynamic Typing
- Subject: Re: Dynamic Typing
- From: Victor Soriano <email@hidden>
- Date: Thu, 28 Mar 2002 15:18:37 -0500
Ondra,
Your ideas made me think of a better way to solve the problem.
My main concern, aside from getting access to the instances of the tab view
controllers, was to make sure that I didn't have multiple instances of each
class allocated. To prevent this, I made each class associated with a page
of the tab view a Singleton. The design pattern guarantees that only one
instance of the class is created. Subsequent attempts to create additional
instances simply return the instance already created. Hence, I solved both
my problems at once.
Your ideas were what got me thinking about this, so thanks for rebooting my
brain!
-Vic
>
>
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.