Xcode iphone sdk - Searching in UITableView, different pattern matching

Posted by Lorenzo on Stack Overflow See other posts from Stack Overflow or by Lorenzo
Published on 2011-01-17T08:08:33Z Indexed on 2011/01/17 8:53 UTC
Read the original article Hit count: 223

Hi everyone, I'm coding a UITableView with a UISearchBar to search between a list of cities (loaded in the uitableview)

Here is my code for searhing:

- (void) searchTableView {
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];

for (NSDictionary *dictionary in listOfItems)
{
    NSArray *array = [dictionary objectForKey:@"Cities"];
    [searchArray addObjectsFromArray:array];
}

for (NSString *sTemp in searchArray)
{
    NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];

    if (titleResultsRange.length > 0)
        [copyListOfItems addObject:sTemp];
}

[searchArray release];
searchArray = nil;}

And with this everything works fine, but i need to do something a bit different. I need to search only between items that match pattern Word* and not * Word *.

For example if I search "roma", this need to match just with "Roma" or "Romania" and not with "Castelli di Roma". Is that possible with this searchbar? How can i modify this? Thanks

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about uitableview