如何实现searchfunction到UITextView?

我有超过40个视图与他们各自的UITexView 。 我想实现一个searchfunction,允许用户search整个UITextViews 。 其实,我甚至不知道如何实现1 UITextViewsearchfunction。 所以我不知道是否有可能。

我已经search了networking,并在这里find,但没有find我所期待的。

我感谢你的build议。

这是一个相当简单的(我可以说明显吗?)的任务。 只是想一点。 在文本视图中search是什么意思? 那么,这意味着得到它的文本,看看是否一个特定的string(search的string)是文本的子string,如果是的话,它是在哪里。 假设您使用UISearchBar来保存要search的文本:

 NSString *subs = searchBar.text; NSString *wholeText = textView.text; NSRange r = [wholeText rangeOfString:subs]; if (r.location == NSNotFound) { // The term to be searched couldn't be found... } else { // The string to be searched for is in the text view, r.location contains where exactly it is. } 

你可以像这样在TextView中search文本:

 [TextView.text rangeOfString:] 

没有内置的控制器来searchUITextView,你必须通过上面的函数来自己实现这个function。