using KVO to update an NSTableView filtered by an NSPredicate
Posted
by KingRufus
on Stack Overflow
See other posts from Stack Overflow
or by KingRufus
Published on 2010-05-20T03:17:34Z
Indexed on
2010/05/20
9:00 UTC
Read the original article
Hit count: 240
My UI is not updating when I expect it to.
The application displays "projects" using a view similar to iTunes -- a source list on the left lets you filter a list (NSTableView) on the right. My filters update properly when they are examining any simple field (like name, a string), but not for arrays (like tags).
I'm removing a tag from one of my objects (from an NSMutableArray field called "tags") and I expect it to disappear from the list because it no longer matches the predicate that is bound to my table's NSArrayController.
ProjectBrowser.mm:
self.filter = NSPredicate* srcPredicate =
[NSPredicate predicateWithFormat:@"%@ IN %K",
selectedTag,
@"tags"];
Project.mm:
[self willChangeValueForKey:@"tags"];
[tags removeAllObjects];
[self didChangeValueForKey:@"tags"];
I've also tried this, but the result is the same:
[[self mutableArrayValueForKey:@"tags"] removeAllObjects];
Interface Builder setup:
- a ProjectBrowser object is the XIB's File Owner
- an NSArrayController (Project Controller) has its Content Array bound to "File's Owner".projects
- Project Controller's filter predicate is bound to "File's Owner".filter
- NSTableView's column is bound to "Project Controller".name
© Stack Overflow or respective owner