按照本答案 Custom UITableViewCell selection style?中关于如何为UITableViewCell创建自定义选择样式的建议,我做了以下操作. 首先,在我的自定义视图控制器中,它有一个UITableView作为属性,并作为其数
首先,在我的自定义视图控制器中,它有一个UITableView作为属性,并作为其数据源和委托我有以下内容:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//UITableViewCell *cell;
NavTableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
那么这是我的整个自定义UITableViewCell:
#import "NavTableViewCell.h"
@implementation NavTableViewCell
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
if(highlighted){
self.contentView.alpha = .5;
}else{
self.contentView.alpha = 1;
}
}
@end
我也尝试将代码放在setSelected中.在这两种情况下,我都没有看到所选/突出显示的表格视图单元格中的任何更改.我尝试过更改颜色并更改其中标签的颜色,但根本没有变化.我也尝试过为单元格选择所有类型的选择样式,只要看到我的自定义就无济于事.
我究竟做错了什么?
从文档:You can use selectedBackgroundView to give the cell a custom appearance when it is
selected. When the cell is selected, this view is layered above the
backgroundView and behind the contentView.
因此,无论您在选择单元格时想要对单元格执行什么操作,都必须为selectedBackgroundView执行此操作.
