子类化uiView>无法识别的选择器

时间:2014-02-05 08:07:03

标签: ios objective-c uiview subclass

我正在尝试将UIView子类化为BottomNavBar(下面的代码)。 我收到以下错误

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

有人可以帮忙解决这里出了什么问题吗?

1 个答案:

答案 0 :(得分:3)

  

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

删除此行。您的视图已经初始化,现在您正在用简单的UIView替换self的值。

我很惊讶你在这里没有看到编译器警告。