TomG103
TomG103

Reputation: 312

UIButton untouchable

I have a NSDictionary that holds the set of objects that will be used in an array to create as many as needed. I have a delete button in the upper right corner of the image and for some reason, I'm unable to click it. I'll write it out...

-(void)addItemsToSomething:(NSMutableArray*)array
{

    for (NSDictionary *item in array)  {

    UIImageView *container....

    UIImageView *boxInContainer....

    UIButton *delete = [UIButton new];
    delete.frame = CGRectMake(70, -4, 24, 26);
    delete.userInteractionEnabled = YES;
    [delete setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
    [delete addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
    [boxInContainer addSubview:delete];

    some math....
}
more math
}

-(void)delete:(id)sender
{
    NSLog(@"Do I work");
}

The NSLog never shows in the logs nor does the button shadow to show it's been touched. I even set the userInteractionEnabled to YES just to try and cover another base but the button still stares me in the face and won't click. Thanks for the help.

This is all placed on a scrollview as well, forgot that part.

Upvotes: 2

Views: 370

Answers (2)

Guntis Treulands
Guntis Treulands

Reputation: 4762

Problem is that You place it on UIImageView. UIImageView has userInteractionEnabled set to NO by default. Simply change boxInContainer.userInteractionEnabled = YES; and button should work!

Oh, and if boxInContainer is subview of container, then You must also set container.userInteractionEnabled = YES;

Upvotes: 2

arturdev
arturdev

Reputation: 11039

I think, that your parent container view is out of his superView's bounds. To check that, try so set clipToBounds property to YES for superview of your parent container view, and see, is still your button visible?

Upvotes: 1

Related Questions