如何将didSelectRow颜色从蓝色变为橙色?

时间:2011-05-05 10:49:47

标签: iphone objective-c uitableview

Cell已经有一张图片(大小为320 * 103)和文字“来自'Raly以恢复理智和......的高点和低点”,如第一个单元格所示。

我的问题是当我选择任何行导航到detailsViewController时,cellimage(大小为320 * 103)颜色应该如下图所示改变imageColor(橙色)(例如第三行)。我怎么能这样做?

Image

3 个答案:

答案 0 :(得分:1)

试试这段代码: - 把代码放在给定的方法中

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];
myBackView.backgroundColor = [UIColor colorWithRed:253.0/256.0 green:199.0/256.0 blue:235.0/256.0 alpha:1.0];// change the color to your orange color i used different color herer
cell.selectedBackgroundView = myBackView;
[myBackView release];
}

答案 1 :(得分:1)

UIView *cellBgView = [[UIView alloc] initWithFrame:cell.frame];
cellBgView.backgroundColor = [UIColor orangeColor];
cell.selectedBackgroundView = cellBgView;
[cellBgView release];

答案 2 :(得分:0)

首先,您需要像其他人所说的那样设置backgroundView。 其次,当选择单元格时,它会调用-(void)setSelected:animated:的{​​{1}}和-(void)setHighlighted:animated:。我想你的单元格是自定义的,从UITableViewCell继承。

我想覆盖UITableViewCell方法,在方法内部,我会做以下事情。

-(void)setHighlighted:animated:
相关问题