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

发布于 2024-12-23 18:13:21 字数 1582 浏览 1 评论 0 原文

我正在开发一个应用程序来在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听你说爱我 2024-12-30 18:13:21

在你的单元格中创建UIView。在此 UIView 上获取一个 UILabel。在此 UILabel 上写入 cell 文本。现在,设置 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

}

Make UIView in your cell. Take a UILabel on this UIView. Write the cell text on this UILabel. Now, set that UIView backgroundColor and cell.seletionStyle = none and UILabel backgroundColor = clear.

Now, in:

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

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文