Atma
Atma

Reputation: 29767

clicking button on tableviewcell clicks cell not button

I have simply dragged a custom style button to a cell in storyboards. The problem is that when I press the button, it clicks the cell and not the button.

What could cause this?

Do I need to increase the click area? If so how?

Do I need to bring the button to the front? If so how?

Thanks!

My cell for row at index path looks like:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";
    MainUserViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  [cell initWithStyle:nil reuseIdentifier:nil];
  [cell.descrlptionLabel sizeToFit];
  [cell.userNameButton addTarget:self action:@selector(userNameClicked:) forControlEvents:UIControlEventTouchDown];


    return cell;
}

Upvotes: 0

Views: 228

Answers (1)

Mundi
Mundi

Reputation: 80265

No need for the initWithStyle line in your method. You should eliminate it.

[cell initWithStyle:nil reuseIdentifier:nil];

The cell is dequeued and should already be ready and initialized. You are working with storyboard, obviously, so the dequeue method is guaranteed to return a valid cell, auto-creating it if necessary.

This is most likely messing things up.

Some more things to check: Make sure the button is topmost in your story board file (i.e. the bottom item in the list on the left). Your resizing of the label could cover it otherwise. Also, make sure you did not accidentally set userInteractionEnabled to NO.

Upvotes: 1

Related Questions