2011-03-16 197 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

相關問題