开发者

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 *Fac开发者_如何学JAVAtsCellIdentifier = @"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)


Set the cell's selectionStyle to 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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜