2014-02-05 32 views
-2

我想將UIView作爲BottomNavBar的子類(下面的代碼)。 我收到以下錯誤子類化uiView>無法識別的選擇器

'-[UIView setCenterImage:]: unrecognized selector sent to instance 0x14dc5050' 

設置幾個斷點的地方我想誤差來源於此行

self.centerImage=[UIImage imageNamed:@"icon_OK.png"]; //I used it just for testing it should be as follows: 
self.centerImage=centerIcon; 

BottomNavBar.m

- (id)initWithFrame:(CGRect)frame centerIcon:(UIImage*)centerIcon withFrame:(CGRect)centerFrame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 

     self=[[UIView alloc]initWithFrame:frame]; 
     [self setBackgroundColor:UA_NAV_BAR_COLOR]; 

     //-------------------------------------------------- 
     self.centerImage=[UIImage imageNamed:@"icon_OK.png"]; //for testing 
     //self.centerImage=centerIcon; >>this is the one that should be used 
     self.centerImageView=[[UIImageView alloc]initWithFrame:centerFrame]; 
     self.centerImageView.image=self.centerImage; 
     [self addSubview:self.centerImageView];    
    } 
    return self; 
} 

cropPhoto.m(以顯示該類別的對象...)

CGRect bottomBarFrame = CGRectMake(0, self.view.frame.size.height-UA_BOTTOM_BAR_HEIGHT, self.view.frame.size.width, UA_BOTTOM_BAR_HEIGHT); 
    NSLog(@"UA_icon_ok: %@", UA_ICON_OK); 
    self.bottomNavBar = [[BottomNavBar alloc] initWithFrame:bottomBarFrame centerIcon:UA_ICON_OK withFrame:CGRectMake(0, 0, 90, 45)]; 
    [self.view addSubview:self.bottomNavBar]; 

任何人都可以幫助解決這裏發生的問題嗎?

+0

setCenterImage - >在底部導航欄的.h文件中添加此方法 – santhu

回答

3

self=[[UIView alloc]initWithFrame:frame];

刪除此行。你的視圖已經被初始化了,現在你用普通的UIView替換了self的值。

我很驚訝你沒有在這裏看到編譯器警告。

+0

它不會是一個警告。它在其他自定義方法中的警告,但不是在init類型的方法返回id – santhu

+0

謝謝!我正在爲我們而頭痛,並無法弄清楚。但這完全有道理! – suMi

相關問題