Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a uitableviewcell unclickable on the iphone sdk

Hi I'm trying to have my uitableviewcell rendered inactive so that a user can't click but merely say the data in the cell. I attempt to do so with:

UITableViewCell *cell = nil;
if (indexPath.row < factsCount) {
static NSString *FactsCellIdentifier = @"FactsCell";
cell = [tableView dequeueReusableCellWithIdentifier:FactsCellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

However the cell can still be clicked and highlighted.

Thanks for your help!

like image 831
Atma Avatar asked Jan 12 '10 18:01

Atma


4 Answers

To stop just some cells being selected use:

cell.userInteractionEnabled = NO;

As well as preventing selection, this also stops tableView:didSelectRowAtIndexPath: being called for the cells that have it set.

(but note that it will disable any interactive content within the cells - eg. buttons - for that case, set selectionStyle to UITableViewCellSelectionStyleNone and ignore the tableView:didSelectRowAtIndexPath: call for that cell)

like image 112
JosephH Avatar answered Nov 20 '22 05:11

JosephH


Set the cell's selectionStyle to UITableViewCellSelectionStyleNone.

like image 23
Ole Begemann Avatar answered Nov 20 '22 05:11

Ole Begemann


This can be done with:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

or

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
like image 34
Atma Avatar answered Nov 20 '22 07:11

Atma


To disable cell selection you can implement -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath method in table view delegate and return nil if you don't want cell with given NSIndexPath to be selected.
As already pointed in other answers to disable cell highlighting you should set its selectionStyle property to UITableViewCellSelectionStyleNone.
Also make sure that you set properties correctly when reusing tableviewcells

like image 4
Vladimir Avatar answered Nov 20 '22 07:11

Vladimir