Re: NSArrayController not rearranging correctly
Re: NSArrayController not rearranging correctly
- Subject: Re: NSArrayController not rearranging correctly
- From: Ken Thomases <email@hidden>
- Date: Tue, 17 Jul 2012 19:14:17 -0500
On Jul 17, 2012, at 4:41 PM, Markus Spoettl wrote:
> I have an NSArrayController (automaticallyRearrangesObjects = YES) on which I set a filterPredicate in code (not through bindings). Most of the time, rearranging works but in one 100% reproducible case, the controller produces an empty arrangedObjects array when it should produce a non-empty one.
>
> It always happens if a certain predicate (A) was set before the predicate that produces the wrong result (B) is set. If any another predicate (or none) is set when setting (B), arrangedObjects is correctly populated. This is completely reproducible.
>
> When I call rearrangeObjects on the array controller, the result gets rectified. However, even with automaticallyRearrangesObjects = NO, the array controller rearranges automatically so when I rearrange manually after setting the filter, I get two KVO change notifications for arrangedObjects which can be very costly and I'd really like to avoid that.
>
> Any ideas on how to force NSArrayController to (1) either produce a correct result automatically or (2) prevent to do any rearranging by itself when a filterPredicate is set?
I would check if an exception has been thrown during the setting of the filter, thus interrupting it from rearranging the objects. My suspicion is that you have a KVO-compliance bug that means that it can't unregister an observation.
By the way, I would not expect automaticallyRearrangesObjects == NO to prevent rearranging when a new filter predicate is set. That property is about whether or not the array controller watches the relevant properties of the content objects so that, if they change in a manner which would affect whether they're filtered or how they're sorted, the array controller rearranges them. It doesn't have to do any such elaborate watching to know to rearrange its objects when the filter predicate or sort descriptors themselves change.
Good luck,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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