On 21 Sep, 2009, at 18:36, Quincey Morris wrote:

On Sep 20, 2009, at 13:51, Colin Howarth wrote:

It's really frustrating. The examples I find either don't seem to fit what I'd like to do (NSMutableArray - NSArrayController - NSTableView). And/or they use ancient versions of IB (which keeps changing). Or they don't use IB at all. Or, like me, they just mention some settings, but ignore others - like "Table View Attributes >> Control >> State: Enabled" or "Array Controller Attributes >> Object Controller >> Editable (yes)". Sometimes I see columns bound. Sometimes ControllerKey is "selections" sometimes it's "arrangedObjects". And nothing works. The documentation only makes sense when you know exactly what it's talking about. :-(

Use arrangedObjects, not selection. You'd bind to arrayController.selection if you were doing a master-detail kind of interface. In your case, you're showing all of the "arranged" (possibly sorted and filtered) content, hence arrayController.arrangedObjects.

Got it.

You have another problem. Your array controller is going to get unarchived before the flow of control reaches applicationDidFinishLaunching and your content array is created. That means the array controller's content is nil, and that's never going to change because you're updating the "elements" property non- KVO-compliantly in applicationDidFinishLaunching.

Perfect analysis. :-) Thanks.

I moved the content array creation to 'init'  and it worked.
I then used

        el_ptr = [elements objectAtIndex:0];
        [el_ptr setPosition: [NSNumber numberWithDouble: 8.0]];

to set values in applicationDidFinishLaunching. And that works too. So now I can get rid of all that debugging code, and do it properly :-) I think I can just use scalars (doubles) instead of NSNumbers, no?

BTW

[elements objectAtIndex:0] setPosition: [NSNumber numberWithDouble: 8.0]];

appears to confuse the compiler. It warns:

######################################################
Multiple methods named '-setPosition:' found
Using '-(void)setPosition:(CGPoint)_value'
Also found '-(void)setPosition:(NSNumber *)_value'

which, of course, results in an error:

Incompatible types for argument 1 of 'setPosition:'
######################################################


This is interesting (the compiler only knows that 'elements' is an NSMutableArray. Not what it's an array of.) I think it's interesting because it *assumes* I want -(void) setPosition:(CGPoint)_value.

While Aaron Hillegass assures me that I *will* love Cocoa (eventually) it appears to me that the combination of dynamic type resolving (?) at runtime AND Interface Builder, where you don't have explicit code to look at, makes it really difficult for the compiler to do its good old fashioned job of checking for MISTAKES. And, yes, Cocoa and IB makes me feel stupid sometimes :-)


In the short term you could try re-setting the array controller's content array programmatically at the end of applicationDidFinishLaunching. That's not really the correct answer, though. The correct answer probably involves moving your window to its own XIB file, and sorting out your KVO compliance issues.

I think I have the KVC/KVO sorted. What's the advantage to having multiple XIB files? Does it speed up the initial startup (if things are only loaded when needed)? I admit I find it (mildly) irritating that the single XIB I have is called MainMenu.xib ...

Thanks for the help.
_______________________________________________

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