I have a textview with a large text, and I would like to find all the occurrences of a string (search) inside it and every time i press search scroll the textView to the range of the current occurrence.
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To do a forward search on text view, use the following snippet –
Basically we use the
NSStringsrangeOfString:options:range:method to find the text and then highlight the text usingselectedRangeand make it visible usingscrollRangeToVisible:.Now once found you can find the next occurrence by modifying the search range.
You can also search backwards by declaring
and then passing
(NSCaseInsensitiveSearch|NSBackwardsSearch)in theoptions.