Showing posts with label selection. Show all posts
Showing posts with label selection. Show all posts

Monday, February 1, 2010

How to Disable UITableCell Selection

Sometimes you just want to show a list (UITableView) without selecting any row. By default a table (cell) is selectable, so how to disable it. What worked for me was defining each cell separately as non-selectable:

cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
...
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

You could also try controlling the whole table, but it didn't work for me:

- (void)viewDidLoad
{
// Prevent message cell selection
self.chatTableView.allowsSelection = NO;
// HOX: not iPhone 2.2.1 compatible --> crash
[super viewDidLoad];
}

This is also supposed to work, but I recall I still got a selection flash:


- (NSIndexPath *) tableView:(UITableView *)_tableView willSelectRowAtIndexPath:(NSIndexPath *)_indexPath
{
// Return nil if you don't want the row selected.
// Hox: interferes with didSelectRowAtIndexPath
return nil;
}