iPhone-是否可以重写UITableViewCell setSelected:animated [英] iPhone - Is it ok to override UITableViewCell setSelected:animated
问题描述
我正在绘制自定义UITableViewCells。我的单元格是不透明的,并已完全绘制在单元格的drawRect中以帮助提高性能。我想自己处理选定单元格的外观。如果我不这样做,那么所添加的selectedBackgroundView将覆盖单元格的内容。覆盖我的单元格的setSelected:animated方法是常见还是可接受的,因此可以正确完成此操作。我猜想如果这样做的话,我就不会调用super的setSelected方法,因为我将处理单元格如何显示其已选择状态。我还必须设置该单元格的选定属性。
I am drawing custom UITableViewCells. My cells are opaque and are completely drawn in the drawRect of the cell to help with performance. I want to handle the look of a selected cell myself. If I don't, then the contents of my cell is covered up by the selectedBackgroundView that is added. Is it common or acceptable to override the setSelected:animated method of my cell so this is done properly. I guess if I did that, then I would not call the super's setSelected method since I would be handling how the cell will show that its selected. I would also have to set the selected property of the cell.
任何帮助都会很棒。谢谢。
Any help would be great. Thanks.
推荐答案
您可以覆盖-[UITableViewCell setSelected:animated:]
,但您应始终在实现中调用super的实现。不这样做可能会对其他与选择相关的行为产生意想不到的影响。
You can override -[UITableViewCell setSelected:animated:]
, but you should always call the super's implementation in your implementation. Not doing so could have have unanticipated effects on other selection-related behaviors.
如果您不希望超类由于选择而进行任何样式更改,只需将单元格的 selectionStyle
属性设置为 UITableViewCellSelectionStyleNone
。
If you don't want the superclass to make any styling changes as a result of the selection, just set the cell's selectionStyle
property to UITableViewCellSelectionStyleNone
.
这篇关于iPhone-是否可以重写UITableViewCell setSelected:animated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!