开发者

TableViewCell color not changing on tapping

When I am tapping on my table view cell, its background color is not changing to blue. Any reason for this?

On tapping of a cell, I am putting a check mark on right view of the cell and if I tap on same cell which has the checkmark, cell glows with blue background color but not on the cell which do not contain the checkmark.

I tried

[iTableView cellForRowAtIndexPath:iIndexPath].selectionStyle = UITableViewCellSelectionStyleBlue;

in my

- (void)tableView:(UITableView *)iTableView didSelectRowAtIndexPath:(NSIn开发者_开发问答dexPath *)iIndexPath {

but it is not helping.


Try setting the cell's selectionStyle in tableView:cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Cell setup

    cell.selectionStyle = UITableViewCellSelectionStyleBlue; // or Gray/None

    return cell;
}


Or you can also do this by this way

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

        UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
        cell.textLabel.shadowColor = [UIColor redColor];
        [cell.contentView setBackgroundColor:[UIColor greenColor]];
        [cell setBackgroundColor:[UIColor magentaColor]];

    }

You can change the color of textlabel,cell,cell's content view. Hope this would also help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜