Andrew
Andrew

Reputation: 16051

UIButton not receiving clicks

So this is the code i have:

    UIButton *svObjectButton = [UIButton buttonWithType:UIButtonTypeCustom];

    svObjectButton.frame = CGRectMake(0, 0, 100, 100);

    [svObjectButton addTarget:self action:@selector(svObjectTouchUpInside) forControlEvents:UIControlEventTouchUpInside];       
    [svView addSubview:svObjectButton];

    UIButton *removeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    removeButton.frame = CGRectMake(0, 0, 20, 20);
    [removeButton addTarget:self action:@selector(removeButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [svObjectButton addSubview:removeButton];
    [svObjectButton bringSubviewToFront:removeButton];

But for some reason all touches on removeButton go straight through to svObjectButton.

Any ideas?

Upvotes: 0

Views: 287

Answers (2)

user141302
user141302

Reputation:

I hope you are adding one small button on another big button. To achieve this, you can add one UIView (for example buttonView) with big button frame size on svView. After that you can add both buttons on buttonView (UIview). You have to avoid:

[svObjectButton addSubview:removeButton];

Upvotes: 1

tonklon
tonklon

Reputation: 6767

Why does the removeButton have to be a subview of the svObjectButton?

I think the problem lies in a UIButton being subview of a UIButton. Try adding the removeButton to svView instead.

Upvotes: 0

Related Questions