On Jun 25, 2009, at 20:02, Peter Zegelin wrote:

Go easy on me here - but I just have a regular NSTableView - no subclass. The NSViewController - which is subclassed -is the delegate and handles numberOfRowsInTableView/ objectValueForTableColumn. So why didn't my question make sense?

Eek! I confused myself. What I said would have been the right answer if it wasn't the wrong answer.

Actually, the answer is pretty much the same -- you should set a valid number of columns in the view controller's initializer, not in its awakeFromNib. That means you're actually going to have to give it an initializer if it doesn't have one already.

The only problem with Graham's band-aid approach is that now you've baked the concept of "numColumns == 0 means the view controller hasn't been initialized yet" into your implementation. What if, in the future, something else that references numColumns gets called before awakeFromNib?

After all, the non-band-aid way is almost as easy:

- (id) initWithNibName: (NSString*) nibNameOrNil bundle: (NSBundle*) nibBundleOrNil {
        self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];
        if (!self)
                return nil;
        numColumns = 8;
        return self;
}

(I'm assuming that the view controller is not itself if a nib file. If it is, you need to used initWithCoder instead.)

This is definitely the right answer this time. If it isn't the wrong answer.


_______________________________________________

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