2011-10-20 37 views
1

我一直在使用CPLockController類很快樂。但自從升級到4.2的Xcode,我一直得到以下警告:「可能無法響應'initWithStyle:'」Xcode 4.2中的警告

'CPLockController' may not respond to 'initWithStyle:' 

無論此行是在代碼:

CPLockController *lockController = [[CPLockController alloc]initWithStyle:(UITableViewStyle)CPLockControllerTypeAuth]; 

在CPLockController.m文件的實現是:

- (id)initWithStyle:(CPLockControllerStyle)theStyle { 
    if(self == [super init]){ 
     self.style = theStyle; 
     self.retry = NO; 
     self.tempString = [NSMutableString string]; 
     self.hideCode = YES; 
    } 

    return self; 
} 
CPLockControllerStyle的

和類型定義:

typedef enum { 
CPLockControllerTypeAuth, 
CPLockControllerTypeSet 
} CPLockControllerStyle; 

我甚至在github中創建了一個問題,但直到現在還沒有回覆!

請指導...謝謝!

回答

3

這是因爲開發者在類聲明中沒有聲明-initWithStyle:。如果你檢查CPLockController.h-initWithStyle:不存在。

我不知道爲什麼開發商沒有這樣做(也許他忘記了,在這種情況下,你應該提交一個bug),但你可以很容易的聲明添加到CPLockController.h如下:

@interface CPLockController : UIViewController <UITextFieldDelegate> { 
    // Bunch of ivars 
} 

// Bunch of properties 

- (void)setTitle:(NSString *)title; 
- (id)initWithStyle:(CPLockControllerStyle)theStyle; // <-- add this line 
@end 
+0

Thx ...但現在警告更改爲'警告:從枚舉類型'UITableViewStyle'隱式轉換爲不同的枚舉類型'CPLockControllerStyle'[-Wconversion,3]' – BufferStack

+1

@Tajar這是因爲您明確地將其轉換爲'(UITableViewStyle)'。刪除該演員。 – 2011-10-20 07:05:51

+0

謝謝!超級專家幫助超級noob! – BufferStack

相關問題