[英]How to simulate allowsSelection on a UITableView before iPhone OS 3.0?
On OS 3.0, when allowsSelection = NO, it's not possible to select any row and it also cancels row highlighting. 在OS 3.0上,当allowsSelection = NO时,无法选择任何行,并且还会取消突出显示行。
On pre OS 3.0, the most obvious solution to disallow selection is to return nil in willSelectRowAtIndexPath, which is part of UITableViewDelegate 在OS 3.0之前的版本中,最明显的禁止选择的解决方案是在willSelectRowAtIndexPath中返回nil,这是UITableViewDelegate的一部分
However, there are two problems with this approach: 但是,此方法存在两个问题:
1) It's not stable (ie from time to time a row do get selected...) 1)不稳定(即有时会被选中...)
2) It is not canceling row highlighting 2)这不是取消行突出显示
Any clue? 有什么线索吗?
You should set the selectionStyle
on the individual UITableViewCell
s that you don't want to be selectable to UITableViewCellSelectionStyleNone
. 你应该设置
selectionStyle
对个人UITableViewCell
是你们等不想可选择以UITableViewCellSelectionStyleNone
。 For those you do want selectable, UITableViewCellSelectionStyleBlue
. 对于那些您想选择的对象,
UITableViewCellSelectionStyleBlue
。 Essentially: 实质上:
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//...
cell.selectionStyle = (canSelectRow ? UITableViewCellSelectionStyleBlue : UITableViewCellSelectionStyleNone);
return cell;
}
To cancel row highlighting you can set cell's selectionStyle to UITableViewCellSelectionStyleNone. 要取消突出显示行,可以将单元格的selectionStyle设置为UITableViewCellSelectionStyleNone。
Returning nil from willSelectRowAtIndexPath has always worked for me... 从willSelectRowAtIndexPath返回nil一直对我有用...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.