简体   繁体   中英

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!

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)

将单元格的selectionStyle设置为UITableViewCellSelectionStyleNone

This can be done with:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

or

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM