xiz*_*zor 1 objective-c uitableview ios
我为我的应用程序实现了一个自定义UITableViewCell,并创建了一个自定义背景视图和selectedbackgroundview,两者都很好用.但是,我在单元格上有几个其他图像和uilabels,我想改变选择它时的颜色.我已经覆盖了以下方法,并且在选择单元格时它会正确记录,但它不会更改图像或文本颜色.
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
if (selected) {
NSLog(@"setSelected:YES");
separatorImage.image = [UIImage imageNamed:@"SeparatorSelected"];
titleLabel.textColor = [UIColor whiteColor];
} else {
NSLog(@"setSelected:NO");
separatorImage.image = [UIImage imageNamed:@"Separator"];
titleLabel.textColor = [UIColor grayColor];
}
}
Run Code Online (Sandbox Code Playgroud)
任何想法我做错了什么?
更新
separatorImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Separator"]]];
[separatorImage setFrame:CGRectMake(99, 4, 5, 71)];
separatorImage.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:separatorImage];
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(111, 4, 188, 26)];
titleLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:21.0];
titleLabel.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:titleLabel];
Run Code Online (Sandbox Code Playgroud)
我有一种预感,发送-setSelected:animated:到super在方法开始时防止更改您的细胞.尝试将呼叫移至super方法的末尾.您还应该覆盖,-setHighlighted:animated:否则您的选择将显得滞后.
| 归档时间: |
|
| 查看次数: |
1392 次 |
| 最近记录: |