选择单元格时如何编辑uitableviewcell的背景色

选择单元格时如何编辑uitableviewcell的背景色,uitableview,background,push-notification,didselectrowatindexpath,Uitableview,Background,Push Notification,Didselectrowatindexpath,我正在开发一个应用程序,在uitableview中显示推送通知。如果用户尚未显示通知,则打印该通知的单元格的背景颜色为灰色。 所以当视图加载到 cellForRowAtIndexPath 方法查看是否未显示通知将单元格背景更改为灰色,并在显示通知时保留默认值 if([shown isEqualToString:@"no"]){ cell.contentView.backgroundColor = [UIColor lightGrayColor]; cell.textLabel.

我正在开发一个应用程序,在uitableview中显示推送通知。如果用户尚未显示通知,则打印该通知的单元格的背景颜色为灰色。 所以当视图加载到

cellForRowAtIndexPath
方法查看是否未显示通知将单元格背景更改为灰色,并在显示通知时保留默认值

if([shown isEqualToString:@"no"]){
    cell.contentView.backgroundColor = [UIColor lightGrayColor];
    cell.textLabel.backgroundColor = [UIColor lightGrayColor];
    cell.detailTextLabel.backgroundColor = [UIColor lightGrayColor];
}
cell.textLabel.text = [NSString stringWithFormat:@"Notifica del %@",data];
cell.detailTextLabel.text = message;
我想改变背景颜色的白色相同的风格,当我不触摸背景颜色加载时,当用户点击单元格

我这样做:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *not = [notification objectAtIndex:indexPath.row];
NSArray *stringArray = [not componentsSeparatedByString:@"---"];
NSString *message = [stringArray objectAtIndex:0];
NSString *data = [stringArray objectAtIndex:1];
NSString *shown = [stringArray objectAtIndex:2];
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor whiteColor];
cell.textLabel.backgroundColor = [UIColor whiteColor];
cell.detailTextLabel.backgroundColor = [UIColor whiteColor];
UIAlertView *popUp = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Notifica del %@",data] message:message delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[popUp show];
[popUp release];
}
结果是所有单元格都变成了白色,隐藏文本并显示警报,但当我单击另一个单元格时,第一个单击的单元格再次变成了以前的样子,新单击的单元格变成了白色。。我该怎么办?您能帮我吗?

在您的手机中创建UIView。在此UIView上创建UILabel。在该标签上写入单元格文本。现在,设置UIView backgroundColor和cell.seletionStyle=none和UILabel backgroundColor=clear

现在,在

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

 change your view background color and uilabel color. shortly change color of cellview and cell text color

}
这只是一个建议,也许对你有帮助