UITextView 中简单链接的最佳方法
我正在创建一个字典查找应用程序。用户从 UITableView 中选择一个单词,应用程序将显示其定义。在某些情况下,该单词与另一个单词相似,因此我想显示“另请参阅:”,然后显示相似单词的列表,当触摸这些单词时,会显示另一个定义。
在此处搜索 UITextViews 内的链接时,大多数答案都涉及链接到网络,这并不是我真正需要的。我只是想在用户触摸某个单词时获得控制权,以便我可以更改视图。
UIWebView 是执行此操作的唯一方法,还是我错过了 SDK 中明显的内容?另外,我更愿意留在本机 SDK 中,而不是走 Three20 路线。
谢谢!
I am creating a dictionary lookup application. The user selects a word from a UITableView and the app displays the definition. In some cases the word will be similar to another word, so I want to display "See Also:" followed by a list of similar words that when touched, bring up another definition.
In searching here on links within UITextViews, most of the answers involve linking out to the web, which is not really what I need. I simply want to get control when the user touches a word so that I can change the view.
Is UIWebView the only way to do this, or did I miss something obvious in the SDK? Also, I'd prefer to stay within the native SDK and not go the three20 route.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将使用另一个
UITableView
来完成这项工作。您的相似单词列表可能已经采用NSArray
格式,因此可以很容易地设置另一个UITableView
而不是UITextView
来显示列表,并且考虑到您已经有了适用于主UITableView
的代码,您已经知道如何使它们可点击!I would use another
UITableView
to make this work. Your list of similar words will probably be inNSArray
format already, so it would be pretty easy to set up anotherUITableView
instead of aUITextView
to display the list, and given that you already have this code working for the mainUITableView
, you already know how to make them clickable!恐怕 UIWebView 将是唯一适合这里的东西。数据检测器是在 UITextView 内部链接的唯一方法,它们只会响应适当的数据类型(电话号码、网页、地址)...
链接可以通过正常方式完成:
设置 webviewdelegate 来捕获任何链接请求(并阻止它们在浏览器中打开),以便您可以在自己的处理程序中打开它们:
A UIWebView will be the only thing that suits here I'm afraid. Data detectors are the only way to link inside of a UITextView, and they will only respond to the appropriate data types (Phone number, web page, address)...
Links can be done the normal way:
Setup the webviewdelegate to snag any link requests (and prevent them from being opened in the browser) so that you can open them in your own handler: