我正在开发一个应用程序以在 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];
}
结果是所有单元格都变成完全白色(隐藏文本)并出现警报,但是当我点击另一个单元格时,第一次点击变成像以前一样再次点击的新单元格变成完全白色..我该怎么办?你能帮助我吗?