How to set a default filter on an NSTableView so that no data is displayed if NSSearchField is empty?

  • Hi,

    is there an elegant/easy way to achieve this?

    The scenario:
    Target 10.5 on OS 10.6 (10.5 may be given up in the future).
    Cell based table view bound to core data.
    Controller set to prepares content, so all the data is loaded.
    On entering a string into an NSSearchField the data is filtered.
    This is pretty default and works.

    What I want to see:
    The table view comes up empty.
    On entering a string, the table view displays the filtered data.
    I clear the string and the table view goes blank again.

    How could I achieve this?

    I guess I could check for an empty string in controlTextDidChange: and set a predicate which is tailored not to find any matches, but somehow I'd rather find a way to execute a precise fetch using the NSSearchField instead of unnecessarily loading a lot of bloat into memory and only to narrow that down again for display.

    At least this is how I assume the standard controller filter bindings work - or does the filtering really execute a fetch on core data behind the scenes? If the latter is the case it would eventually suffice to prevent data from being displayed for empty filter values.

    Any insights?
    Has anybody done something like this?

    Any pointers are appreciated!

    Thanks!

    Peter
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today