【发布时间】:2023-03-21 13:42:01
【问题描述】:
我正在开发一个应用程序,该应用程序接收我在 UIWebView 中显示的提要。提要有嵌入的链接,我想在 Safari 而不是 WebView 中打开这些链接。我查看了此处发布的其他几个问题。我不确定我错过了什么,但我认为这很简单。这是我的 .h 和 .m 文件
#进口 @class 博客Rss; @interface EnduranceDailyWorkoutViewController : UIViewController { IBOutlet UIWebView * descriptionTextView; BlogRss * currentSelectedBlogItem; } @property (nonatomic, 保留) UIWebView * descriptionTextView; @property (readwrite, retain) BlogRss * currentSelectedBlogItem; @结尾#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 中没有正确链接一样。
【问题讨论】: