How to perform searching based on characters starting in ios

…衆ロ難τιáo~ 提交于 2019-12-24 01:37:38

问题


Hi in my ipad application am performing searching operation using searchbar.For performing thise searching operation i am using following logic

  1. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!