sol
sol

Reputation: 319

iphone table view - button inside table cell

I have created a button and placed it inside a table cell:

[btn addTarget:self action:@selector(doSomething:) forControlEvents:UIControlEventTouchUpInside];
...
[cell.aSubView addSubview:btn];

The button shows up in the table cell, but tapping it highlights and selects the entire cell. How can I just get the button to be selected on its own?

Upvotes: 1

Views: 1149

Answers (2)

BojanG
BojanG

Reputation: 1922

Set your cell's selectionStyle property to UITableViewCellSelectionStyleNone. Make sure tableView:didSelectRowAtIndexPath: handles the tap on the cell properly (e.g. ignores it if that is what you want).

Upvotes: 0

fabian789
fabian789

Reputation: 8412

Why do you use cell.aSubView? You should go with the contentView property. From the documentation:

If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.

Upvotes: 1

Related Questions