我正在开发一个应用程序,它接收我在UIWebView中显示的提要。 Feed已嵌入我希望在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中没有正确链接的东西。
答案 0 :(得分:1)
您需要确保将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]];
}