Re: Set a view's delegate using IB
Re: Set a view's delegate using IB
- Subject: Re: Set a view's delegate using IB
- From: Quincey Morris <email@hidden>
- Date: Wed, 07 Sep 2011 14:12:26 -0700
On Sep 7, 2011, at 13:20 , Luc Van Bogaert wrote:
> I have a nib file that contains a "main" view object. This nib file's "file's owner" is set to be the "main" viewcontroller. The "main" view object in this nib has an outlet for a "delegate" property. I want to connect this outlet to an "other" viewcontroller. So, I decided to instantiate this "other" viewcontroller by adding a viewcontroller object to the "main" nib file. This causes 'awakefromnib' to be called a first time on the "other" viewcontroller.
>
> On the other hand, this "other" viewcontroller itself is the "file's owner" of an "other" nib. When running the program, this causes 'awakefromnib' to be called on the "other" viewcontroller a second time.
There's something code-smelly about putting a view controller (or a window controller, for that matter) in a nib file at all. There's also something code-smelly about using the other view's view controller as the delegate of the first view (although I'm guessing it sounds a lot more reasonable in the context of the actual design relationship between the two views). I can't claim that you've blatantly abused view controllers, though.
OTOH, what you've saved by setting things up this way (I'm guessing) is two lines of code in the "main" view controller -- one to instantiate the subsidiary view controller manually and one to set a delegate on the main view. That's not a very impressive saving, considering that to achieve it you have to transgress some of the usual encapsulation patterns of views and view controllers.
Specifically, I guess I'm propounding the design question: what behavior is the main view delegating, and why is it delegating it to a *view controller*?
(That's a somewhat rhetorical question, BTW. I'm not calling on you to account for your design, just suggesting you consider whether your object graph is perhaps missing a separate delegate object.)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden