选择单元格时如何编辑 uitableviewcell 的背景颜色
我正在开发一个应用程序来在 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];
}
结果是所有单元格变得全白(隐藏文本)并出现警报,但是当我单击另一个单元格时,第一个单击的单元格再次像以前一样,单击的新单元格变为全白..我该怎么办?你能帮助我吗?
i'm developing an app to show push notification in a uitableview. If notification is not yet shown by user, the cell that print that notification has gray background color.
So when view is loaded in
cellForRowAtIndexPath
method i see if notification is not shown changing cell's background to gray and leaving it default if notification is shown
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;
I want to change color of background in white ( the same style when i don't touch background color on load) when users clicks on cell
i do this:
- (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];
}
the result is that all the cell become totally white ( hiding texts ) and alert appear, but when i click on another cell, the first clicked become again like before and new cell clicked become totally white.. how can i do? can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的单元格中创建
UIView
。在此UIView
上获取一个UILabel
。在此UILabel
上写入cell
文本。现在,设置 UIView backgroundColor 和 cell.seletionStyle = none 和 UILabel backgroundColor = clear。现在,在:
Make
UIView
in your cell. Take aUILabel
on thisUIView
. Write thecell
text on thisUILabel
. Now, set thatUIView backgroundColor
andcell.seletionStyle
= none andUILabel backgroundColor
= clear.Now, in: