Update predicate on arraycontroller

683 views Asked by At

I have an array controller and I have bound an entity to it, sort descriptor and predicate. If I change the predicate format when the app runs, it works, so the binding is working.

My problem is when I want to change the predicate, f.ex. with a search term or some string that a user inputs, nothing happens, but when I add a record to the core data database, the tableview does update.

So my question is, how do I tell the array controller that the predicate has changed and it should update itself. Here is a code that runs when I enter search term, it also works, and I get all the NSLogs output correctly. Just my tableview is not updating itself.

- (IBAction)didChangeSearch:(id)sender {
    if (sender == searchField) {
        NSString *searchterm = [sender stringValue];
        if (searchterm.length > 1) {
            predicate = [NSPredicate predicateWithFormat:@"name contains [c]%@", @"m"];
            NSLog(@"Putting predicate to the job : %@", searchterm);

        } else {
            predicate = nil;
            NSLog(@"There is nolonger any predicate");
        }
    }
    NSLog(@"I just got %@", [sender stringValue]);
}

I would like to say in the start that I am very new to bindings, have never used them until tonight, got a good feeling for them, and liked it, saves me so much code and I finally understood it (as much as 1 day can).

1

There are 1 answers

1
rdelmar On BEST ANSWER

You should use self.predicate = ..... This will ensure that the proper KVO notifications are sent out, which will make your tableview update immediately (this assumes that "predicate" is a property and is bound to your array controller's filter predicate binding).