2011-11-29 70 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 
相關問題