2011-01-19 225 views
0

我正在使用以下代码来扩展Web视图委托。iPhone - 扩展UIWebViewDelegae协议

@protocol CustomWebViewDelegate <UIWebViewDelegate> 
@optional 
-(void)touchesEnded; 
@end 

在我的课,我实现Web视图代表:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
- (void)webViewDidFinishLoad:(CustomWebView *)webView 
- (BOOL)webView:(CustomWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType: 

我的接口声明如下:

@interface BrowserView : UIViewController <UITextFieldDelegate, UIWebViewDelegate, UIScrollViewDelegate, CustomWebViewDelegate> 

的问题是,它不是调用Web的代表视图。为什么? 我的代码错在哪里?

回答

0

您需要将BrowserView对象实际设置为UIWebView的代表才能获得回调。你不能只声明自己符合协议,并期望获得回调。例如: -

BrowserView.m:

- (void)viewDidLoad { 
    ... 
    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; 
    webView.delegate = self; 
    [self.view addSubview:webView]; 
    ... 
} 
+0

是的,我设置web视图的委托为好。 – Satyam 2012-01-17 07:15:27