如何在 UI Web 视图中打开 UITextView URL?
在我的 iPhone 应用程序中,UITextView 包含一个 URL。我想在 UIWebView 中打开这个 URL,而不是在 safari 中打开它? 我的 UITextView 包含一些数据和 URL。在某些情况下,没有。 URL 的数量可以多个。
谢谢 沙
In my iPhone app an UITextView is containing an URL. I want to open this URL in an UIWebView instead of opening it into safari?
My UITextView contains some data along with an URL. In some cases the no. of URLs can be more than one.
Thanks
Sandy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以按照以下步骤操作:
UITextView
中勾选以下属性。或者为动态获取的文本视图编写这些属性。
delegate
方法:我想你正在寻找那个。
You can follow these steps:
UITextView
taken from Xib or Storyboard.OR write these for textview taken dynamically.
delegate
method :I think you are searching for that.
UITextView 能够检测 URL 并相应地嵌入超链接。您可以在以下位置打开该选项:
然后您需要配置您的应用程序以捕获此 URL 请求并让您的应用程序处理它。我在 github 上发布了一个样板类来执行此操作,这可能是最简单的路线: http ://github.com/nbuggia/Browser-View-Controller--iPhone-。
第一步是对 UIApplication 进行子类化,以便您可以覆盖对“openUrl”请求采取操作的人员。该类可能如下所示:
接下来,您需要更新 main.m 以将
MyApplication.h
指定为 UIApplication 类的绑定委托。打开 main.m 并将这一行更改为
:最后,您需要实现 [(MyAppDelegate*) openURL:url] 方法,让它对 URL 执行您想要的操作。就像打开一个新的视图控制器,其中包含 UIWebView,并显示 URL。你可以做这样的事情:
希望这对你有用。
The UITextView has the capability to detect URLs and embed hyperlinks accordingly. You can turn that option on in:
Then you need to configure your app to trap this URL request and let your application handle it. I published a boilerplate class on github that does this, which might be the easiest route: http://github.com/nbuggia/Browser-View-Controller--iPhone-.
The first step is to sub-class UIApplication so you can override who gets to take action on the 'openUrl' request. Here's what that class might look like:
Next, you need to update main.m to specify
MyApplication.h
as being the bonified delegate for your UIApplication class. Open main.m and change this line:to this
Finally, you need to implement the [(MyAppDelegate*) openURL:url] method to have it do what ever you would like with the URL. Like maybe open up a new view controller with a UIWebView in it, and show the URL. You could do something like this:
Hopefully that should work for you.
假设您有以下实例,也添加到您的 UIView:
并且 textView 包含 URL 字符串,您可以将 URL 的内容加载到 webView 中,如下所示:
Assuming you have the following instances, that are also added to your UIView:
and textView contains the URL string, you can load the contents of the URL into webView, as follows: