Ios 无法初始化参数,并且我没有';我不明白为什么
我得到这个错误:Ios 无法初始化参数,并且我没有';我不明白为什么,ios,zxing,Ios,Zxing,我得到这个错误: Cannot initialize a parameter of type 'id<ZXingDelegate>' with an lvalue of type 'FirstViewController *const __strong' 我如何解决这个问题?多亏了Macmade的评论,我成功地解决了这个问题。我应该这样写: ZXingWidgetController *widController = [[ZXingWidgetController allo
Cannot initialize a parameter of type 'id<ZXingDelegate>'
with an lvalue of type 'FirstViewController *const __strong'
我如何解决这个问题?多亏了Macmade的评论,我成功地解决了这个问题。我应该这样写:
ZXingWidgetController *widController =
[[ZXingWidgetController alloc] initWithDelegate:***(id)** self showCancel:YES
OneDMode:NO];
其中(id)是他所说的桥牌演员。在本期中使用此换行代码
ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:(id<ZXingDelegate>)self showCancel:YES OneDMode:NO];
ZXingWidgetController*widController=[[ZXingWidgetController alloc]initWithDelegate:(id)self-showCancel:YES-OneDMode:NO];
如果我理解正确,问题不在于您需要桥接转换,而在于您的FirstViewController类没有定义ZXingDelegate接口类,因此这就是问题所在
ZXingDelegate是(基于我猜的名称)接口类(协议或委托),它声明必须由继承它的类定义的函数(接口)(除非它们是@optional)。类似C++中的纯虚拟(抽象)类。
因此,在头文件中需要如下内容:
@interface FirstViewController : UIViewController <ZXingDelegate>
@implementation FirstViewController
//......
-(void) SomeFunctionThat_ZXingDelegate_declares
{
// .... do something here....
}
//......
@end
我想是吧?然后你需要一个桥牌演员。你能解释一下我是怎么做到的吗?是的,Arcnavermind,我在谷歌上搜索了一下,发现了什么是bridget演员。非常感谢您的回答,我希望我能选择一条评论作为答案
@implementation FirstViewController
//......
-(void) SomeFunctionThat_ZXingDelegate_declares
{
// .... do something here....
}
//......
@end