[英]Open Link in UIWebView in Safari
我正在開發一個可接收在UIWebView中顯示的提要的應用程序。 該供稿包含我要在Safari中打開的嵌入式鏈接,而不是要在WebView中打開的鏈接。 我查看了此處發布的其他幾個問題。 我不確定我缺少什么,但是我認為這很簡單。 這是我的.h和.m文件
#import @class BlogRss; @interface EnduranceDailyWorkoutViewController : UIViewController { IBOutlet UIWebView * descriptionTextView; BlogRss * currentlySelectedBlogItem; } @property (nonatomic, retain) UIWebView * descriptionTextView; @property (readwrite, retain) BlogRss * currentlySelectedBlogItem; @end
#import "EnduranceDailyWorkoutViewController.h"
#import "BlogRss.h"
@implementation EnduranceDailyWorkoutViewController
@synthesize descriptionTextView = descriptionTextView;
@synthesize currentlySelectedBlogItem = currentlySelectedBlogItem;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *html = [NSString stringWithFormat:@"%@ %@",currentlySelectedBlogItem.title, currentlySelectedBlogItem.contentEncoded];
[descriptionTextView loadHTMLString:html baseURL:[NSURL URLWithString:nil]];
}
-(BOOL)webView:(UIWebView *)descriptionTextView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (UIWebViewNavigationTypeLinkClicked == navigationType) {
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
return YES;
}
使用Interface Builder,我已經鏈接了IBOutlet和UIWebView。 請讓我知道我想念的東西。 我已經在webView部分中設置了斷點,但是代碼從未在此擊中,因此幾乎就像是IB中沒有正確鏈接的東西。
您需要確保將UIWebView的委托設置為您的控制器。 您可以在界面構建器中執行此操作,也可以修改viewDidLoad方法:
- (void)viewDidLoad {
[super viewDidLoad];
// add this line to set the delegate of the UIWebView
descriptionTextView.delegate = self;
NSString *html = [NSString stringWithFormat:@"%@ %@",currentlySelectedBlogItem.title, currentlySelectedBlogItem.contentEncoded];
[descriptionTextView loadHTMLString:html baseURL:[NSURL URLWithString:nil]];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.