开发者

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:UIControlEve开发者_如何学编程ntTouchUpInside];
...
[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?


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜