How to open UITextView web links in a UIWebView instead of Safari?

来源:互联网 发布:数据结构 java 编辑:程序博客网 时间:2024/05/16 15:02

http://stackoverflow.com/questions/1305544/how-to-open-uitextview-web-links-in-a-uiwebview-instead-of-safari

 

The simplest way is to override thewebView:decidePolicyForNavigationAction:request:frame:decisionListener: method onUITextView 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

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.

Note: this is technically a private API and could be removed at any time. There is no way to do this via the public API.

原创粉丝点击