PDA

View Full Version : subclass of NSArrayController




MrFusion
Feb 28, 2008, 02:32 AM
Hello,

I have a question about good coding practices.

I have a NSTreeController binded to a NSManagedObjectContext, which works fine.
The NSArrayController is binded to the selection of NSTreecontroller. For single selections, everything works fine. But when the selection is zero or multiple the NSArrayController has to return different values, also depending on what is selected.

The problem is that my subclass of NSArrayController complete ignores my code, and goes straight the the NSManagedObjectContext and gives the standard reply of Empty Selection and Multiple Values.



Soulstorm
Feb 28, 2008, 04:07 AM
Hello,

I have a question about good coding practices.

I have a NSTreeController binded to a NSManagedObjectContext, which works fine.
The NSArrayController is binded to the selection of NSTreecontroller. For single selections, everything works fine. But when the selection is zero or multiple the NSArrayController has to return different values, also depending on what is selected.

The problem is that my subclass of NSArrayController complete ignores my code, and goes straight the the NSManagedObjectContext and gives the standard reply of Empty Selection and Multiple Values.

Don't have time to check if my recommendation is right, and I may be total wrong about this... But have you tried creating a category, and not a subclass of the NSTreeController? Maybe you can override functions through this.

MrFusion
Feb 28, 2008, 04:28 AM
Don't have time to check if my recommendation is right, and I may be total wrong about this... But have you tried creating a category, and not a subclass of the NSTreeController? Maybe you can override functions through this.

Category? No, never done anything like this.
Is that similar as adding a protocol to a subclass?

Soulstorm
Feb 28, 2008, 06:02 AM
Category? No, never done anything like this.
Is that similar as adding a protocol to a subclass?

Actually, a protocol lets you add methods into an existing class without altering it. You can do it to improve functionality of existing Cocoa classes. I recommend you consult your book on how to do that, or to read Apple's quick ObjC guide about protocols.

However, I don't know if you can override functions of a class using a protocol. But it's worth giving a shot.