On 06 Sep 2011, at 21:51, Quincey Morris wrote:

> On Sep 6, 2011, at 12:20 , Luc Van Bogaert wrote:
> 
>> I've been struggling trying to set a viewcontroller (loaded by its own nib) 
>> as the delegate of another (main) viewcontroller's view in IB, while at the 
>> same time avoiding  'awakefromnib' being called twice on the former 
>> viewcontroller object, because of it being part of the latter 
>> viewcontroller's nib. I haven't succeeded so far, so I finally decided to 
>> use code. But, I'm still wondering if this is at all possible using IB. Any 
>> ideas?
> 
> It's not clear which of the 2 nib files contains the view controller. You 
> first say it's "loaded by its own nib", then you say it's "part of the [main 
> view controller's] nib". Which is it?

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.

> It's also not clear what the "this" is that you want to do using IB. Clearly, 
> you can't use IB to prevent 'awakeFromNib' being called twice. Why do you 
> care if 'awakeFromNib' is called twice, and if you care why don't you solve 
> the problem it causes in 'awakeFromNib' itself (such as setting a flag to 
> prevent your custom initialization being done twice), for which you're 
> presumably writing code anyway?

The information I found online regarding this "problem" only left me with a 
suspicion that I should always try to avoid 'awakefromnib' being called more 
than once. I didn't suspect that I could very well just ignore it, or just use 
another approach (your suggestion below). 

> Also, you can perhaps take the alternative path of overriding the view 
> controller's 'loadView' instead of 'awakeFromNib'. That should be executed 
> only once, although at a different point in the view life cycle.


This approach seems to work fine, so I'll leave it at this for now. Thanks!

-- 
Luc Van Bogaert




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to