我得到了这个错误:
Cannot initialize a parameter of type 'id<ZXingDelegate>'
with an lvalue of type 'FirstViewController *const __strong'在这行代码中:
ZXingWidgetController *widController =
[[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES
OneDMode:NO];我该如何解决这个问题呢?
发布于 2011-12-05 16:24:00
多亏了Macmade的评论,我设法解决了这个问题。我应该这样写的:
ZXingWidgetController *widController =
[[ZXingWidgetController alloc] initWithDelegate:***(id)** self showCancel:YES
OneDMode:NO];其中(id)是他所说的桥接演员。
发布于 2012-12-10 22:17:53
使用下面这行代码来解决这个问题
ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:(id<ZXingDelegate>)self showCancel:YES OneDMode:NO];发布于 2014-08-07 11:50:24
如果我理解正确的话,问题不是你需要桥接转换,而是你的FirstViewController类没有定义ZXingDelegate接口类,因此问题就出现了。
ZXingDelegate是(我猜是基于名称的)接口类(协议或委托),它声明了必须由继承它的类定义的函数(接口)(除非它们是@optional)。类似于C++中的纯虚拟(抽象)类。
所以在你的头文件中需要类似这样的东西:
@interface FirstViewController : UIViewController <ZXingDelegate>在您的.m文件中,如下所示:
@implementation FirstViewController
//......
-(void) SomeFunctionThat_ZXingDelegate_declares
{
// .... do something here....
}
//......
@endhttps://stackoverflow.com/questions/8308427
复制相似问题