Re: NSViewController awakeFromNib and NSTableView numberOfRowsInTableView
Re: NSViewController awakeFromNib and NSTableView numberOfRowsInTableView
- Subject: Re: NSViewController awakeFromNib and NSTableView numberOfRowsInTableView
- From: Quincey Morris <email@hidden>
- Date: Thu, 25 Jun 2009 19:40:05 -0700
On Jun 25, 2009, at 19:14, Peter Zegelin wrote:
Well I guess the question then becomes 'where is earlier'!
I tried overloading NSViewController::loadView and it also gets
called 'after' the first call to numberOfRowsInTableView.
If I have the 3 methods awakeFromNib, numberOfRowsInTableView and
loadView this is the calling sequence I get:
numberOfRowsInTableView
awakeFromNib
loadView
numberOfRowsInTableView
numberOfRowsInTableView
objectValueForTableColumn <- drawing will start here I guess
Grahams suggestion is a good workaround (thanks!) but I still don't
quite get it.
Specifically, the first thing that's going be called is either
initWithCoder: or init:
http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#/
/apple_ref/doc/uid/10000051i-CH4-SW18
After that, the object is potentially available to other objects --
and itself, of course -- before its awakeFromNib is called. As Keary
said, there's no basis for believing that awakeFromNib is the *first*
method that can possibly be called on a just-unarchived object.
Your situation requires a little care because you (presumably,
otherwise your question wouldn't make sense) have a NSTableView
subclass, but what's archived is actually a NSTableView (according to
the above document, if you dragged a table view into your XIB file in
IB and then changed its class). It gets transmogrified into your
subclass as/after it's unarchived (it says), so you'd better set your
initial state in initWithCoder. If you think about it, your
NSTableView subclass never finished its initialization before it was
archived, and if you create one programatically it will fail in
exactly the same way as when it's being loaded from the nib, for the
same reason. (So you'll have to implement its designated initializer
too, if you might ever create one programatically.) (Alternatively,
follow Graham's approach, which in effect makes initialization
unnecessary.)
If you really want to know what's calling 'numberOfRowsInTableView'
early, set a breakpoint there and look. Could well be the table view
itself.
_______________________________________________
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