我得到这个错误:

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

我该如何解决?

有帮助吗?

解决方案

多亏了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];

如果我正确理解这一点,那么问题不是您需要桥接的铸件,而是您的FirstViewController类并未定义Zxingdelegate接口类,因此问题。

ZxingDelegate是(我猜想)的(基于名称)接口类(协议或委托),该类别声明函数(接口)必须由继承它的类定义(除非它们是@Optional)。诸如C ++中的纯虚拟(摘要)类之类的东西。

因此,您需要在标题文件中进行类似的内容:

@interface FirstViewController : UIViewController <ZXingDelegate>

在您的.m文件中,类似的内容:

@implementation FirstViewController

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


@end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top