2013-05-26 45 views
0

我的代碼存在語義問題。我有一個UIWebView,我添加了一條錯誤消息,所以如果沒有互聯網連接,彈出一個錯誤。setDelegate上的語義問題

這是我的一個UIWebView的編碼在我的.m文件

- (void)viewDidLoad { 
[super viewDidLoad]; 
NSString *fullURL = @"http://example.com"; 
NSURL *url = [NSURL URLWithString:fullURL]; 
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
[website setDelegate:self]; 
[website loadRequest:requestObj]; } 

的錯誤是在此代碼

[website setDelegate:self]; 

它說,它是一個語義問題和錯誤發送FirstViewController * const_strong參數不兼容類型編號

這裏是錯誤消息的代碼,如果沒有互聯網連接

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { 
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error" message:@"error connecting to the internet" delegate:self 
cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 
[alert show]; } 

回答

1

您需要指定FirstViewController實現協議。喜歡的東西:

@interface FirstViewController() <UIWebViewDelegate> 
@end 

編譯器目前警告你,你設置不指定它實現了所以沒有執行編譯檢查所需的協議委託。

0

您的視圖控制器應指定其符合UIWebViewDelegate加入「<UIWebViewDelegate>」的@interface線的末端,無論是在主@interface聲明中.h

@interface MyViewController : UIViewController <UIWebViewDelegate> 

或者私有類擴展(如果有的話)在.m文件:

@interface MyViewController() <UIWebViewDelegate> 

Conforming to Protocols使用Objective-C指南進行編程。