2011-03-16 152 views
0

我正在研究接收我在UIWebView中显示的源的应用程序。 Feed中嵌入了我想在Safari中打开的链接,而不是WebView。我查看了其他几个在这里发布的问题。我不确定我错过了什么,但我认为这很简单。这里是我的.h和.m文件在Safari中的UIWebView中打开链接

 
#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中没有正确链接。

回答

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]]; 
} 
+0

GreginYEG,感谢您的帮助。我忘了设置代表。我以为我在Interface Builder中完成了这个工作,但显然不是。 – James 2011-03-21 09:51:02

相关问题