问题
Hi in my ipad application am performing searching operation using searchbar.For performing thise searching operation i am using following logic
- If any element includes the character what i am entering in search bar, those elements have to pickup from so many elements and display in table.
code:
NSRange rTextRange = [finalSearchingString rangeOfString:searchStr options:(NSCaseInsensitiveSearch)];`
if (range.location != NSNotFound){
[self.filterdList addObject:product];
}
here final results avaialble in filterdList array and that array data i will display in tableview.
Now my issue in this operation is actually now the requirement is changed. New requirement is The product which are starting with searching characters those only have to display not included products. Please help me how to implement this functionality .Thanks in advance.
回答1:
try like this i Hope this one helps you,
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", txtSearch.text];
NSArray *ResultArray = [yourArray filteredArrayUsingPredicate:predicate];
[tableview reloadData];
kept above code in searchBar delegate method and reload the tableview with result array.
来源:https://stackoverflow.com/questions/15783157/how-to-perform-searching-based-on-characters-starting-in-ios