2011-11-29 74 views
5

这是错误我得到:无法初始化参数,我不明白为什么

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]; 

我该如何解决这个问题?

+0

ARC我相信?然后你需要一个桥接模型。 – Macmade

+0

你能解释一下我该怎么做?是的,ARC – Pillblast

+0

没关系,我搜索了一下,发现了一个bridget演员。非常感谢你的回答,我希望我可以选择评论作为答案 – Pillblast

回答

5

感谢Macmade的评论,我设法解决了这个问题。我应该这样写:

ZXingWidgetController *widController = 
    [[ZXingWidgetController alloc] initWithDelegate:***(id)** self showCancel:YES 
                    OneDMode:NO]; 

哪里(id)是他谈论的桥接角色。

1

使用这行代码关闭此问题

ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:(id<ZXingDelegate>)self showCancel:YES OneDMode:NO]; 
0

如果我理解正确的这个,问题不在于你需要桥接演员,而你的FirstViewController类没有定义ZXingDelegate接口类,这样的问题。

ZXingDelegate是(根据我的名字我猜)接口类(协议或委托)声明函数(接口),必须由继承它的类定义(除非他们是@optional)。类似于C++中的纯虚拟(抽象)类。

所以你需要在你的头文件是这样的:

@interface FirstViewController : UIViewController <ZXingDelegate> 

而在你的.m文件,像这样:

@implementation FirstViewController 

//...... 
-(void) SomeFunctionThat_ZXingDelegate_declares 
{ 
    // .... do something here.... 
} 
//...... 


@end 
相关问题