NSListView "filter" a la Mail
NSListView "filter" a la Mail
- Subject: NSListView "filter" a la Mail
- From: Sean Gilbertson <email@hidden>
- Date: Thu, 6 Feb 2003 17:00:43 -0500
Hello all,
I'm looking to apply a "filter"/search field that restricts what's
shown in an NSListView, like the search field in Mail.
In the NSListView.DataSource method "tableViewObjectValueForLocation,"
you can't simply return null because the ListView stops asking for
values once it receives a null. The last solution I tried was to
return the String (this is in Java) if it matched what the user is
searching for, and if the current String doesn't match, it recursively
calls "tableViewObjectValueForLocation" with the next row value. This
poses the problem that a certain match will be reported multiple times,
from the time of the last match until the time of the next match. For
example:
(Searching for:)
ell
(The list:)
ello
hello
yellow (1)
yellow (2)
yellow (3)
(the values in the "yellow" 1 and 2 members of the data array being
represented dont match (perhaps they are "bye" and "bird"), so it
recursively calls til it gets "yellow." The "yellow" number 3 match is
actually "yellow".)
Code snippet:
public Object tableViewObjectValueForLocation(NSTableView
aTableView,
NSTableColumn
aTableColumn,
int rowIndex)
{
if (rowIndex < m_groupList.getNumberOfGroups())
{
if (
((String)aTableColumn.identifier()).startsWith("group") )
{
String filter = m_groupFilter.stringValue().trim();
String groupName =
m_groupList.getGroupNameByIndex(rowIndex);
if (filter.length() == 0)
return groupName;
else if (groupName.indexOf(filter) != -1)
return groupName;
else
return tableViewObjectValueForLocation(aTableView,
aTableColumn,
rowIndex +
1);
}
I assume there's a more simple solution to this than the complex
algorithm(s) I'm going to arrive at with this approach. Any thoughts?
Thanks,
Sean Gilbertson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.