Re: Unable to access customized NSView's accessor method
Re: Unable to access customized NSView's accessor method
- Subject: Re: Unable to access customized NSView's accessor method
- From: James Bucanek <email@hidden>
- Date: Sat, 4 Mar 2006 16:09:22 -0700
Frederick C. Lee wrote on Saturday, March 4, 2006:
>Greetings:
> I noticed that an accessor routine of a customized NSView doesn't
>fire when called. The View did initialize.
> I created a simple 'Hello' routine. But it doesn't fire.
>
>Does anyone know why?
As others have already pointed out, you must have the outlet connected in Interface Builder. Assuming you do...
My other question is _when_ does selectRegion get called? Many NSView classes initialize themselves when they are constructed. This might included performing basic layout, calculating drawing regions, fetching the data model, firing events to its delegate, and so on. When the framework is loading the NIB, objects are being created and connected simultaneously. During this time you have can't assume that *any* connection will be set/valid until the after entire NIB is loaded and the windowControllerDidLoadNIB message is fired.
I got caught by this just last week. I had two NSOutlineViews with two data model objects. Because of the names of the classes, one outline delegate was created after its dataSource object was created and connected and the other outline delegate was being created before its dataSource was created and connected. Figuring out why one worked and the other didn't drove me nuts for about an hour until I realized that the NIB objects and views were getting initialized *during* the NIB loading process when many of the NIB connections hadn't been made yet. When you think about it, it all makes sense -- but I wasn't thinking that clearly at the time.
Lesson learned: Code defensively. Methods should behave well even when connections are not set. If you have to do something (or redo something) that requires all connections to be complete, wait until windowControllerDidLoadNIB has fired.
--
James Bucanek
_______________________________________________
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