0

I have been looking for a tutorial that integrates UISearchBar and UITextView and nothing is available. This makes me wonder, is this possible? I have wrote the following code:

- (IBAction)fileAction:(id)sender {

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"LICENSE" ofType:@"txt"];
    [textView setText:[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]];
}

Where I am reading the document named License.txt

I want to integrate a Search Bar to the View, but how do I make it work? How can I display the results of the search within the Text File? Is this possible? Can anyone provide me with a sample code of this integration?

EmptyStack
  • 51,274
  • 23
  • 147
  • 178
ibjazz
  • 263
  • 5
  • 17

1 Answers1

0

I'm not quite clear on what you want to do. If you want to highlight somehow the search text in a UITextView, you can't. It doesn't support formatted text. You have to use a WebView with HTML or use CoreText with an NSAttributedString.

jschmidt
  • 2,898
  • 3
  • 24
  • 27
  • I only want to include several txt or html documents (for a book) and load them to a UITextView or to a UIWebView, respectively, and include a feature where the user can search with the UISearchBar the document he/she is viewing. But I have only seen people talking about TableViews and SearchBars. I do not want to search a TableView. I want to include a search bar that highlights or redirects you to the text it found on the TextView. – ibjazz Jun 18 '11 at 14:34
  • UIWebView will be easier because you can simply search the string, add additional HTML tags to highlight the text that you want, and then reload the WebView with the new string. – jschmidt Jun 18 '11 at 21:45
  • Do you know of a tutorial that shows you that? Since I have been looking in all the Web, and everything is too complicated. I only want the user to perform a search within the application. thx – ibjazz Jun 19 '11 at 04:15