Programmatic control of Core Data search field
Programmatic control of Core Data search field
- Subject: Programmatic control of Core Data search field
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 03 Jul 2005 11:14:26 -0400
My Core Data application has the usual search field to filter the usual
table view. In IB, I set several search predicate bindings for the search
field. This correctly populates the search field's search menu with several
custom search categories, and choosing one of them manually from the search
menu works as expected, filtering the table view.
Here's the problem: In addition to letting the user choose a search category
manually, I want to do it programmatically from a button's action method.
The only approach I've thought of is to set the desired search menu item to
NSOnState, then send the menu item's action method. However, Cocoa builds
the search menu dynamically, and the search menu template that it exposes
contains only the standard "All" predicate -- the named predicates that I
added in IB are missing. I therefore cannot grab the template, reset its
state, and set the search field cell's menu template again, as I would do if
this were my own search field.
In Xcode debug mode, I can see all my IB predicate menu items in
NSSearchFieldCell's private _searchMenu iVar. I therefore wrote a simple
category on NSSearchFieldCell to return _searchMenu. Now I can get its menu
items (after they were dynamically inserted by Cocoa), set the state of one
of them to NSOnState, and send its action to its target. It works very
nicely.
I am surprised that _searchMenu is private, since NSSearchFieldCell exposes
the other two constituents of the search field: cancelButtonCell and
searchButtonCell.
But since it is private, I wonder if there is a more robust solution?
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
PreFab Software - http://www.prefab.com/scripting.html
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden