ios - 如何更改 UITableView 中选定单元格的颜色?

标签 ios objective-c uitableview

这个问题在这里已经有了答案:





Changing background color of selected cell?

(30 个回答)


7年前关闭。




我正在制作一个应用程序,其中我在 UITableView 中显示我的数据.我被困住了。我想更改所选单元格的颜色。这该怎么做?

以下是我在 -didSelectRowAtIndexPath 中的代码

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"the messageid==%@",[[self.inboxmessagesarray objectAtIndex:indexPath.row ] objectForKey:@"messageId"]);
    manage.messageid=[[self.inboxmessagesarray objectAtIndex:indexPath.row ] objectForKey:@"messageId"];  // here i pass the value to singleton class
    [self performSegueWithIdentifier:@"segueIdentifier" sender:tableView];
}

最佳答案

如下所述更新您的代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"the messageid==%@",[[self.inboxmessagesarray objectAtIndex:indexPath.row ] objectForKey:@"messageId"]);

    manage.messageid = [[self.inboxmessagesarray objectAtIndex:indexPath.row ] objectForKey:@"messageId"];  // here i pass the value to singleton class

    [self performSegueWithIdentifier:@"segueIdentifier" sender:tableView];

    // Add this line to set selected default gray style
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
}

使用 selectionStyle 属性使单元格突出显示。更多详情请引用 UITableViewCellSelectionStyle

关于ios - 如何更改 UITableView 中选定单元格的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27478130/

相关文章:

ios - 在 iOS 7 中重用 UIPickerView 中的 View

objective-c - 应用内购买本地化

ios - SDImageCache - 4.0 迁移后无法识别的选择器错误

ios - 改变 LeveyPopListView 的起点

iphone - UITableView 中的可重用单元格

iOS Present Viewcontroller 出现黑屏

ios - 如果用户已经对应用进行了评分,如何避免向用户显示应用内评论提示

objective-c - 如何将动态创建的 UIWebView 从 loadHTMLString 保存到文档目录?

ios - 停止 UITableView 部分标题在滚动时移动

objective-c - "Entitlement has value not permitted by a provisioning profile",但它没有