Zhen Zhen - 1 year ago 121
Objective-C Question

Button not clickable after adding as a subview to a UIView

I have created a class called

, which is a subclass of
. I added a
as a
as shown in my code below:

-(id)initWithButtonType:(NSString *)type
self = [super init];
if (self)
self.customButton = [self setupButtonWithTitle:type andFrame:frame];
[self addSubview:self.customButton];
self.customButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];

return self;

The problem I am facing is that although the button appears, they are not clickable. Is there something wrong with the way I am adding the buttons to the

enter image description here

EDIT: To add on, I am using this custom button class instance to a cell:

UICustomButton *customButton = [[UICustomButton alloc]initWithFrame:someFrame];
[cell.contentView addSubView:customButton];

Answer Source

check the frame of your UICustomButton object, and if self.customButton is out of its superView.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download