如何在UIWebView而不是Safari中打开UITextView Web链接? [英] How to open UITextView web links in a UIWebView instead of Safari?

查看:94
本文介绍了如何在UIWebView而不是Safari中打开UITextView Web链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发和iPhone 3.0应用程序。我正在尝试将UITextView中的Web链接打开到UIWebView而不是Safari。但仍然没有运气。

I'm developing and iPhone 3.0 application. And I'm trying to open web links in a UITextView into a UIWebView instead of Safari. But still no luck.

UITextView 不可编辑,它可以完美地检测网页链接并在Safari中打开它们。

The UITextView is not editable, and it perfectly detects web links and open them in Safari.

如何避免这种情况?如何获取该URL以便我可以使用我自己的 UIWebView

How to avoid that? How to grab that url so i can use with my own UIWebView?

推荐答案

最简单的方法是覆盖 webView:decisionPolicyForNavigationAction:request:frame:decisionListener: on UITextView 如下所示:

The simplest way is to override the webView:decidePolicyForNavigationAction:request:frame:decisionListener: method on UITextView like so:

@interface UITextView (Override)
@end

@class WebView, WebFrame;
@protocol WebPolicyDecisionListener;

@implementation UITextView (Override)

- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id < WebPolicyDecisionListener >)listener
{
    NSLog(@"request: %@", request);
}
@end

这将影响所有您的应用程序中的UITextView s。如果你只在一个视图上需要这个,请创建一个子类并覆盖该方法。

This will affect all UITextViews in your application. If you only require this on a single view, create a subclass and override the method on that.

注意:这在技术上是一个私有API,可以删除随时。无法通过公共API执行此操作。

编辑:从iOS 7.0开始,在上引入了一种新方法UITextViewDelegate 支持此功能。有关详细信息,请参阅nihad的答案。

edit: as of iOS 7.0 a new method has been introduced on UITextViewDelegate to support this. See nihad's answer for details.

这篇关于如何在UIWebView而不是Safari中打开UITextView Web链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆