我对这段代码有一个问题:
标题:
@interface ViewController : UIViewController {
IBOutlet UITextField *field;
IBOutlet UIWebView <UIWebViewDelegate> *web;
}实施:
@protocol UIWebViewDelegate;
- (void)viewDidLoad{
//some other code here
webView = [[UIWebView alloc] init];
webView.delegate = self;
}我有两个问题。第一个是webView = [[UIWebView alloc] init];</code>the compiler generates the following message:Incompatible pointer types assigning to 'UIWebView*_strong' from 'UIWebView'*'.行上的
The second problem is that I get an error on the line <code>webView.delegate = self;</code> that says:‘将ViewController*const_strong传递给不兼容类型'id'`的参数。
有什么想法吗?任何帮助都将受到欢迎。
发布于 2012-01-16 04:36:49
您已将您的webView ivar声明为UIWebViewDelegate。你的意思是让ViewController成为UIWebViewDelegate
@interface ViewController : UIViewController <UIWebViewDelegate>发布于 2012-01-16 01:31:25
您使用的是NIB吗?因为您在头文件中使用了一个IBOutlet,这意味着您有一个NIB连接到它。在这种情况下,您的web视图将已经创建,并且您不需要alloc/init调用。
另外,您为什么要这样做:
@protocol UIWebViewDelegate;当您想要声明一个协议时,而不是当您想要声明一个类符合它时,就会使用@protocol。也许可以在这里快速浏览一下Apple的文档:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProtocols.html
https://stackoverflow.com/questions/8871561
复制相似问题