iPhone - 扩展UIWebViewDelegae协议
问题描述:
我正在使用以下代码来扩展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的代表视图。为什么? 我的代码错在哪里?
答
您需要将BrowserView
对象实际设置为UIWebView
的代表才能获得回调。你不能只声明自己符合协议,并期望获得回调。例如: -
BrowserView.m:
- (void)viewDidLoad {
...
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
webView.delegate = self;
[self.view addSubview:webView];
...
}
是的,我设置web视图的委托为好。 – Satyam 2012-01-17 07:15:27