Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stadidas

macrumors regular
Original poster
Feb 27, 2006
243
0
Kent, United Kingdom
Hi all,

I have been writing an application in which I have an NSArrayController binding an instance of NSMutableArray to a NSTableView. When I insert objects using the insert: action of the array controller, a new object appears in the table view as expected. However, I have another method which adds objects directly to the mutable array. The problem is when I do this the table view does not update until the insert: method is called again. I assume this is because I am bypassing the bindings layer.
Is there any way of accessing the array controller’s insert: method programmatically? If not, how can I have the table view refresh itself when a new object is added to the mutable array?

Thanks for any help you can give, if you need any more detail just ask.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Use the array controller's add: method to add objects to it directly, not to the array. If you setAutomaticallyPreparesContent:YES (can be enabled in IB), then you don't even need to manage an array - you just have to work with the array controller, and it'll update automatically.
 

stadidas

macrumors regular
Original poster
Feb 27, 2006
243
0
Kent, United Kingdom
Use the array controller's add: method to add objects to it directly, not to the array. If you setAutomaticallyPreparesContent:YES (can be enabled in IB), then you don't even need to manage an array - you just have to work with the array controller, and it'll update automatically.

Thanks kainjow, that sounds great.
How do I access the array controller from my document class? At the moment I was using the insert: method by attaching a button in IB (but this isn't how I want to do it, it was just to check it worked). Once I can access the array controller from code I will be able to implement your solution.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Just setup an IBOutlet for the NSArrayController, and then you can access it directly.

Edit: it might be better to use addObject: or addObjects:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.