Modifying NSMutableArray controlled by NSArrayController
Modifying NSMutableArray controlled by NSArrayController
- Subject: Modifying NSMutableArray controlled by NSArrayController
- From: email@hidden
- Date: Tue, 13 Sep 2005 04:47:03 -0700
Hello list,
Can I modify the NSMutableArray "under" the NSArrayController that
controls it? Here's what I'm doing:
I've got an NSMutableArray* in my controller class, with an accessor
("foo") for it. I did the following in IB:
1. Created an NSObjectController and connected the content outlet of
the NSObjectController to my controller instance.
2. Created an NSArrayController and set the bindings contentArray to
the selection of the NSObjectController, with model key path "foo".
3. Added an NSTableView with one column, and set the table column's
value binding to the NSArrayController's arrangedObjects.
If I populate the NSMutableArray with a couple objects in my init
method, those objects display in the table. Everything works as
expected so far, but I run into trouble when programatically adding
items to the NSMutableArray.
If I add an item to the NSMutableArray, the table does not update to
show the new item. I added a reference to the table view in IB and
tried [tableView reloadData], but no joy.
I did manage to get it to work by adding a reference to the
NSArrayController to my controller class and wiring it up in IB, then
changing code to call [arrayController addObject:] instead of
[fooArray addObject:]. Is this the recommended idiom? Is it okay to
have a reference to the NSArrayController in my controller class like
this? It seems funny to need a reference to the array and a reference
to the array controller (which has a reference to the array).
Am I doing this right?
Thanks.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden