Re: Unbinding NSArrayController's contentArray
Re: Unbinding NSArrayController's contentArray
- Subject: Re: Unbinding NSArrayController's contentArray
- From: Antonio Nunes <email@hidden>
- Date: Thu, 8 Mar 2007 00:25:40 +0000
On Mar 7, 2007, at 11:25 PM, I. Savant wrote:
On Mar 7, 2007, at 6:20 PM, Antonio Nunes wrote:
I want to temporarily unbind a controller from its source array,
change the array's contents and re-establish the binding. The
problem is that the above recipe doesn't seem to work:
Why sever the binding when you can just build an array of the
objects to add separately, then call:
[theController addObjects:myNewObjectsArray];
... that seems far easier.
My thoughts exactly, with the added complication that I need to
insert rather than add, so I wrote something using
replaceObjectsInRange:withObjectsFromArray: but that did not stop the
way the tableView was updating, and resulted in the same problems I
was having before. So I looked into severing the bind. But your
posting made me rethink my strategy and I realised I may well have
made a mistake in my initial attempt, and/or that I would probably be
better off using insertObjects:atIndexes:. After the replaceObjects…
attempt failed I didn't think the insertObjects… method would make
any difference so I did not try it, but now I did, something along
the lines of:
[myArray insertObjects:newArray atIndexes:[NSIndexSet
indexSetWithIndexesInRange:NSMakeRange(startIndex, [newArray count])]];
[myArrayController rearrangeObjects]
This has the desired effect, so I suppose the way
replaceObjectsInRange:withObjectsFromArray: inserts the objects is
significantly different from the way the insertObjects:atIndexes:
method does it. Among other things I need to tell the array
controller to rearrangeObjects, which wasn't necessary with the
replaceObject… method.
It still leaves me curious though as to why I couldn't successfully
unbind the array controller as suggested by the Apple docs.
Cheers,
António
----------------------------------------------------
It isn't so important to do great things,
as to do what you do with great love.
----------------------------------------------------
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden