I create a class: MyArrayController, which is a subclass of NSArrayController and bind the it to a table.
I need to pass a person object to MyArrayController object, like using method:
-initWithPerson:(Person *)person;
but because MyArrayController is created automatically (because I don’t alloc it explicitly, I think it is created by Cocoa automatically), I can’t get the object of MyArrayController or init it explicitly.
What can I do to set a person object to MyArrayController?
The typical way to do this is not to use an
NSArrayControllersubclass. From your description you are not trying to change the behavior ofNSArrayControlleryou are just trying to specify its content. The way to do this is to put anNSArrayControllerin your nib file and bind it to your table. Add anIBOutletto yourNSWindowControllerorNSViewControllerthat is bound to theNSArrayController. Create and pre-populate anNSArraywith the content you want to display in the table. Then in yourawakeFromNiborwindowDidLoadmethod you callsetContent:to set the content array for theNSArrayControllerto theNSArrayyou created. Roughly like: