Re: [Solved] Re: NSTableView: no display until header clicked
Re: [Solved] Re: NSTableView: no display until header clicked
- Subject: Re: [Solved] Re: NSTableView: no display until header clicked
- From: Quincey Morris <email@hidden>
- Date: Mon, 5 Oct 2009 11:55:16 -0700
On Oct 5, 2009, at 10:52, David Hirsch wrote:
This seems to be precisely the solution. The problem was that the
bound object didn't know about changes to the array. There are two
ways to inform it: manipulate the array through the controller, or
fire my own KVO. In fact, here is the latter solution in the Apple
docs:http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/
Conceptual/KeyValueObserving/Concepts/AutoVsManual.html#//apple_ref/
doc/uid/20001844 (listing 3).
Or are you suggesting that I should be notifying using some other key?
I'm suggesting that you have a data model (an array property of your
document), a mediating controller (the NSArrayController) that has a
derived property (arrangedObjects, derived from the data model), a
user interface object (the NSTableView), and, incidentally a
coordinating controller (the NSDocument subclass, or its
NSWindowController).
The problem isn't in "arrangedObjects". The problem is that your data
model isn't (apparently) being updated KVO compliantly:
- (id) init... {
...
myArrayIvar = [NSMutableArray array];
...
}
- (void) awakeFromNib {
...
[myArrayIvar addObject: someObject]; // oops, not KVO compliant
...
}
If that's what's going wrong, then the solution is, most directly:
- (void) awakeFromNib {
...
[[self mutableArrayValueForKey: @"myArrayPropertyName"] addObject:
someObject]; // KVO compliance FTW
...
}
Or, indirectly:
- (void) awakeFromNib {
...
[myArrayController addObject: someObject];
...
}
(because the behavior of the latter is to add the object KVO
compliantly to the data model array on your behalf)
Which solution you chose depends on other factors (for example, the
second one requires that your document subclass have an outlet to the
array controller, which as a design choice has its own set of
considerations).
Usually, if you find yourself using willChange/didChange, then
something has gone wrong and you've leaped into hackland -- though, to
be sure, there are non-controversial situations where using them is a
viable choice.
_______________________________________________
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