2012-12-24 71 views
0

我試圖將UILabel pageTitle更改爲顯示在UIWebView上的頁面的標題。我沒有回覆警告或錯誤,只是沒有改變。從已加載的WebView獲取頁面標題

ViewController.h

@interface ViewController : UIViewController <UITextFieldDelegate, UIWebViewDelegate, UIActionSheetDelegate> { 
    UIWebView *_webView; 
    UILabel *_pageTitle; 

} 

@property (nonatomic, retain) IBOutlet UIWebView *webView; 
@property (nonatomic, retain) IBOutlet UILabel *pageTitle; 

@end 

ViewController.m

- (void)webViewDidFinishLoad:(UIWebView *)webView { 

    self.pageTitle.text = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"]; 
    [_webView setDelegate:self]; 

} 

IB的截圖

Screenshot of IB

+0

您記得您的UIWebView的委託設置爲視圖控制器,這樣webViewDidFinishLoad:被稱爲? – simonbs

回答

1

你應該叫[_webView setDelegate:self];viewdidLoad/loadView所以它可以調用UIWebViewDelegate