问题描述
我正在开发和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
?
推荐答案
最简单的方法是覆盖 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 UITextView
s in your application. If you only require this on a single view, create a subclass and override the method on that.
编辑:从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链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!