选中后,如何更改UITableView行的颜色? [英] How do I change the color of a UITableView row when it is selected?

查看:157
本文介绍了选中后,如何更改UITableView行的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找有关此问题的答案,但尚未找到可行的方法.我要做的就是能够更改背景颜色或我选择的UITableView行的图像.

I've looked around for answers to this but have yet to find one that works. All I want to do is to be able to change the background color, or image of the UITableView row that I select.

当我选择一行时,我习惯于仅转换视图,但是这次我希望能够更改该行的属性.我知道要使用indexPath.row更改哪一行,但是我不知道如何更改行的外观,因为已经调用了cellForRowAtIndexPath方法!

I am used to just transitioning views when you I select a row, but this time I want to be able to change that rows properties. I know which row I want to change, with indexPath.row, but I don't know how I would go about changing how the row looks because the cellForRowAtIndexPath method has already been called!

我该怎么做才能改变颜色?

What can I do to change the color?

推荐答案

您将这样做:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //First you get the cell you want to change
    UITableViewCell* theCell = [tableView cellForRowAtIndexPath:indexPath];

    //Then you change the properties (label, text, color etc..) in your case, the background color
    theCell.contentView.backgroundColor=[UIColor redColor];

    //Deselect the cell so you can see the color change

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

只需确保在回收电池时考虑这种颜色变化即可.

Just make sure you consider this color change when you recycle cells.

如果您需要更多信息,请发表评论.

If you need more info just post a comment.

这篇关于选中后,如何更改UITableView行的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆