Advance search implementation in iphone?

后端 未结 2 706
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 02:25

I want to implement advance search functionality so that if a particular text is typed in search bar, the list of contents in UITableview should be filtered based on the sea

2条回答
  •  独厮守ぢ
    2020-12-16 03:13

    I haven't tried something like this myself but my approach would be as follows:

    1. Implement the method textField:shouldChangeCharactersInRange:replacementString: in your UITextFieldDelegate object. This method will get called for every character that is entered or deleted from your textField.

    2. In the above delegate method, based on the current text content in the TextField, perform your search and return a list(array) of results.

    3. Take the array and for each result construct a custom UITableViewCell. This cell should have a UIWebView whose text is an excerpt of your search result.

    4. For the highlighting, you need to perform a search-replace in the text you are about to render in the WebView to find the search string, say foo for example, and replace it with foo or any other HTML formatting you may wish to apply. You can use the standard NSString API - (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement to do the find-replace.

    Hope this helps.

提交回复
热议问题