开发者

Xcode iphone sdk - Searching in UITableView, different pattern matching

I'm coding a UITableView with a UISearchBar to search betwe开发者_运维技巧en 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


You should check if (titleResultsRange.length > 0 && titleResultsRange.location == 0) instead of just (titleResultsRange.length > 0)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜