2011-04-25 51 views
0

我正在处理分析后数据来自服务器的应用程序,并在自定义tableview单元格中显示这些数据,例如标题,标题和图像,它们具有单元格图像[渐变图像]和这些图像是动态生成的。选择导航到另一个viewcontroller类后,我想更改图像背景颜色[橙色]。任何人都请帮助我。它非常紧急。如何更改选定的单元格颜色

谢谢先进。

回答

0

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

方法

编辑: 你可以做

CustomTableCell *cell = (CustomTableCell *)[table cellForRowAtIndexPath:indexPath]; 
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
backView.backgroundColor = [UIColor orangeColor]; 
cell.backgroundView = backView; 

或与该小区过什么。

+0

我会覆盖 - (void)setSelected:(BOOL)selected动画:(BOOL)表视图单元格的动画方法... – JustSid 2011-04-25 12:15:00

+0

嗨它不显示单元格的橙色。 – pinku 2011-04-25 13:55:09

+0

我在customcell.m中的代码 – pinku 2011-04-25 14:05:06

2

斐伊川,

使用

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath { 

的图像:

cell.selectedBackgroundView = [[[UIImageView alloc] init] autorelease]; 

UIImage *img = [UIImage imageNamed:@"yourImage.png"]; 
    ((UIImageView *)cell.selectedBackgroundView).image = img; 

的颜色:

cell.selectedTextColor = [UIColor yourcolor] 
0

我认为最好的方法是:

UIView *view = [UIView alloc] initWithFrame:CGRectMake(0 ,0 , cell.frame.size.width, cell.frame.size.height]); 
view.backgroundColor = ....; 

cell.selectedBackgroundView = view; 
相关问题