Quick filter help

Discussion in 'iPhone/iPad Programming' started by links2004osx, Feb 24, 2009.

  1. macrumors newbie

    Joined:
    Feb 24, 2009
    #1
    I currently have a search bar in my app that is pulling its results from the first character of a cell's title. However, my search would be far better if it were to filter from anywhere in the cell title (string). That is, if I type "A", not only would "Apple" come up, but so would "Orange" and "Strawberry".

    Any help would be greatly appreciated as I think I'm missing something quite obvious,

    Here's everything I'd think you'd need to help:

    Code:
    - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
    {
    	[filteredListContent removeAllObjects];
    	
    	NSMutableDictionary *cellTitle;
    	for (cellTitle in stories)
    	{
    		NSComparisonResult result = [[cellTitle objectForKey:@"title"] compare:searchText options:NSCaseInsensitiveSearch
    																		 range:NSMakeRange(0, [searchText length])];
    		if (result == NSOrderedSame)
    		{
    			[filteredListContent addObject:cellTitle];
    		}
    	}
    	
    	[Table reloadData];
    }
     
  2. thread starter macrumors newbie

    Joined:
    Feb 24, 2009
    #2
    Again, I must ask, any ideas? Surely I'm not the only one confused about how to change the search strings to filter rather than search.
     
  3. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    You will need to do something other than using compare: then.

    P.S. Don't bump. It's not polite.
     

Share This Page