打开从UIWebView到Safari(iphone)的链接
好吧,与其试着用文字解释我的问题,不如看我录制的这个小视频 下面是详细视图控制器(webview所在的页面)的代码 detailViewController.h打开从UIWebView到Safari(iphone)的链接,iphone,uiwebview,mobile-safari,hyperlink,Iphone,Uiwebview,Mobile Safari,Hyperlink,好吧,与其试着用文字解释我的问题,不如看我录制的这个小视频 下面是详细视图控制器(webview所在的页面)的代码 detailViewController.h #import <UIKit/UIKit.h> #import "MWFeedItem.h" @interface DetailViewController : UIViewController <UIWebViewDelegate> { MWFeedItem *item; NSString
#import <UIKit/UIKit.h>
#import "MWFeedItem.h"
@interface DetailViewController : UIViewController <UIWebViewDelegate> {
MWFeedItem *item;
NSString *summaryString;
IBOutlet UILabel *titleLabel;
IBOutlet UIWebView *contentLabel;
//IBOutlet UILabel *dateLabel;
IBOutlet UIScrollView *textScroller;
}
@property (nonatomic, retain) MWFeedItem *item;
@property (nonatomic, retain) NSString *summaryString;
@property (nonatomic, retain) IBOutlet UILabel *titleLabel;
@property (nonatomic, retain) IBOutlet UIWebView *contentLabel;
@end
注意:尽管上面写着“contentLabel”,但它是一个UIWebView。它是旧版本遗留下来的
谢谢 实现-(BOOL)webView:(UIWebView*)webView应与请求一起加载:(NSURLRequest*)请求导航类型:(UIWebView导航类型)导航类型
然后您可以这样做:
NSURL* url = [request URL];
if (UIWebViewNavigationTypeLinkClicked == navigationType)
{
[[UIApplication sharedApplication] openURL:url];
return NO;
}
非常感谢。我唯一需要更改的是,在委托实现中,将第二个“webView”改为“contentLabel”(我的webView的名称),然后将“return YES;”放在您展示给我的代码的花括号外。非常感谢。
NSURL* url = [request URL];
if (UIWebViewNavigationTypeLinkClicked == navigationType)
{
[[UIApplication sharedApplication] openURL:url];
return NO;
}