Re: filterPredicate not effecting NSArrayController
Re: filterPredicate not effecting NSArrayController
- Subject: Re: filterPredicate not effecting NSArrayController
- From: Erik Stainsby <email@hidden>
- Date: Thu, 22 Nov 2012 16:08:27 -0800
Thanks for leading this horse to water, Ken.
I removed the arrayController from the NIB and set the tableView's Content to File's Owner > peopleArrayController.arrangedObjects and VOILA.
*sigh* I seem to consistently try to put too much into the (nib/code) and get in the way of the services provided by the frameworks.
I'll learn… someday.
On 2012-11-22, at 3:47 PM, Ken Thomases <email@hidden> wrote:
> Could you be calling your -updateFilter: method prior to the NIB being loaded?
>
> Also, did you say the peopleArrayController property is weak? If so, then that's why it's nil. There's no strong reference to the array controller you're allocating, so it gets deallocated, and weak references are nil'ed out.
>
> Your original message said the array controller is instantiated in the NIB. So why are you instantiating another one here? peopleArrayController should just point to the one from the NIB.
>
> Regards,
> Ken
>
> On Nov 22, 2012, at 9:38 AM, Erik Stainsby wrote:
>
>> And then I stuck in
>>
>> NSAssert(self.peopleArrayController, nil);
>>
>> which failed. Now I'm simply confused…
>>
>> - Erik
>>
>> On 2012-11-22, at 7:33 AM, Erik Stainsby <email@hidden> wrote:
>>
>>> Sorry Ken, didn't articulate that well.
>>>
>>> The peopleArrayController is instantiated in the XIB, and then content is populated using the outlet in code:
>>>
>>> - (void) awakeFromNib {
>>>
>>> ABAddressBook * abk = [ABAddressBook addressBook];
>>>
>>> NSMutableArray * temp = [NSMutableArray new];
>>> for(ABPerson * abp in [abk people]) {
>>> RSPerson * rsp = [[RSPerson alloc] initWithABPerson:abp];
>>> [temp addObject:rsp];
>>> }
>>>
>>> NSSortDescriptor * lastNameSort = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES selector:@selector(localizedStandardCompare:)];
>>> NSSortDescriptor * firstNameSort = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES selector:@selector(localizedStandardCompare:)];
>>> // NSSortDescriptor * orgNameSort = [[NSSortDescriptor alloc] initWithKey:@"organization" ascending:YES selector:@selector(localizedStandardCompare:)];
>>> NSArray * sortedArray = [temp sortedArrayUsingDescriptors: @[lastNameSort,firstNameSort]]; //,orgNameSort]];
>>>
>>> self.people = [NSMutableArray arrayWithArray:sortedArray];
>>> self.peopleArrayController = [[NSArrayController alloc] initWithContent:self.people];
>>>
>>> [self.tableView reloadData];
>>> }
>>>
>>> This works to populate the tableView using bindings in the XIB. Therefore I assume that the peopleArrayController is not nil.
>>>
>>> ~ Erik
>>>
>>>
>>>
>>> On 2012-11-22, at 3:31 AM, Ken Thomases <email@hidden> wrote:
>>>
>>>> I don't understand. That's a non sequitur. I wasn't asking about the table view and what it displays. I was asking whether an outlet was properly connected and whether the code in question was being run after the NIB had loaded and connected the outlet.
>>>>
>>>> Regards,
>>>> Ken
>>>>
>>>> On Nov 21, 2012, at 9:30 PM, Erik Stainsby wrote:
>>>>
>>>>> Yes. The table view displays this same content.
>>>>>
>>>>> Erik
>>>>>
>>>>> On 2012-11-21, at 6:42 PM, Ken Thomases <email@hidden> wrote:
>>>>>
>>>>>> On Nov 21, 2012, at 6:27 PM, Erik Stainsby wrote:
>>>>>>
>>>>>>> [self.peopleArrayController setFilterPredicate: nil];
>>>>>>
>>>>>>> [self.peopleArrayController setFilterPredicate:p];
>>>>>>
>>>>>>> [self.peopleArrayController setFilterPredicate:cp];
>>>>>>
>>>>>>> [self.peopleArrayController rearrangeObjects];
>>>>>>> [self.tableView reloadData];
>>>>>>
>>>>>>> The tableView is bound to an arrayController object in XIB, which is in turn a ref to this (weak) peopleArrayController in the windowController.
>>>>>>>
>>>>>>> The predicates (whichever is triggered) print to log just as expected. But the contents of the tableView are not reduced.
>>>>>>> The table displays the entire contents of the peopleArrayController.arrangedObjects unfiltered.
>>>>>>>
>>>>>>> Is there another step required?
>>>>>>
>>>>>> Have you verified that self.peopleArrayController is not nil?
>>>>>>
>>>>>> Regards,
>>>>>> 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