在我的UITableViewCell子类中,我重写了setHighlighted和setSelected方法,以便在选中时更改单元格的外观,但每当我在任一方法中设置accessoryView属性时,我所有其他代码都会更改字体和阴影颜色完全被忽略。
例如,使用此代码将更改文本和详细信息标签的文本颜色
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
if (selected) {
self.textLabel.textColor = [UIColor whiteColor];
self.textLabel.shadowColor = [UIColor clearColor];
self.detailTextLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.shadowColor = [UIColor clearColor];
}
}
但是当我将自定义accessoryView添加到混合中时,所有其他代码都会被忽略,但是accessoryView图像会出现。
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
if (selected) {
self.textLabel.textColor = [UIColor whiteColor];
self.textLabel.shadowColor = [UIColor clearColor];
self.detailTextLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.shadowColor = [UIColor clearColor];
self.accessoryView =
[[UIImageView alloc] initWithImage:styleImage(@"/icons/disclosure_selected.png")];
}
}
我有什么问题吗?如何在选定和突出显示的状态期间正确自定义accessoryView和单元格代码的其余部分?
答案 0 :(得分:0)
我最终只是创建了自己的UIImageView并隐藏了内置的UIImageView。
答案 1 :(得分:-2)
我认为accessoryView是UIButton而不是UIImageView ...... 试试这个:
accessory = [UIButton buttonWithType:UIButtonTypeCustom];
[accessory setImage:[UIImage imageNamed:@"/icons/disclosure_selected.png"] forState:UIControlStateNormal];
accessory.frame = CGRectMake(0, 0, 26, 26); //You can change it
accessory.userInteractionEnabled = YES; //You can change it too
self.accessoryView = accessory;
希望它会有所帮助