Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UItableViewCell - don't allow to select the cell, but can still press buttons inside it?

Can you add a button as a subview to a uitableview cell and have that clickable, but not the cell itself. ie: I don't want the selected view to come up. Obvs I can just not have the cell disclose anywhere, but I don't want it to look "selected" when someone taps it.

Setting user interaction enabled to NO makes the whole thing unenabled, including the buttons.

Any ideas?

Thank you.

Tom

like image 730
Thomas Clayson Avatar asked Oct 17 '10 18:10

Thomas Clayson


People also ask

How do I turn off cell selection?

If you want to disable selection for just some of the cells, use: cell. userInteractionEnabled = NO; As well as preventing selection, this also stops tableView:didSelectRowAtIndexPath: being called for the cells that have it set.

How do you deselect a row in Swift?

deselectRow(at:animated:) Deselects a row that an index path identifies, with an option to animate the deselection.

What is Uitableview in Swift?

A view that presents data using rows in a single column.


2 Answers

cell.selectionStyle = UITableViewCellSelectionStyleNone;

This will prevent the cell to highlight for a bit before the willSelect returns nil

like image 92
Sander Avatar answered Nov 15 '22 18:11

Sander


implement this delegate method:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

and set the UITableViewCells selectionStyle property to UITableViewCellSelectionStyleNone

like image 20
Matthias Bauch Avatar answered Nov 15 '22 18:11

Matthias Bauch