单击时的UItableViewCell背景颜色 [英] UItableviewcell background color while click

查看:104
本文介绍了单击时的UItableViewCell背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在uitableview中未选中的情况下为选中或选中的整个单元格设置颜色并重置为以前的颜色?我尝试过,但是它显示了背景颜色几秒钟.任何人都可以帮助我编写代码.

How to set a color to the entire cell which selected or checkmarked and reset to previous color while in unchecked in uitableview?I tried but it showing a background color for a sec.can any one please help me to code.

推荐答案

好,在这里,我想您要在选中单元格时给单元格上色,而如果未选中,则要另一种颜色,使那些选中的单元格保持以前的颜色.因此,全局具有数组状态.在didSelectRowAtIndexPath中:

Ok, here I think you want to color your cell when selected and another color if unselected,leaving those selected cells with the previous color. So have an array states globally. In didSelectRowAtIndexPath :

if (![myMutableArray containsObject:indexPath]) {
    [myMutableArray addObject:indexPath]; 
}
else{
    [myMutableArray removeObject:indexPath];
}

[sampleTableView reloadData];

在cellForRowAtIndexPath中:

And in cellForRowAtIndexPath :

if ([myMutableArray containsObject:indexPath]) {
    cell.backgroundColor = [UIColor redColor];
}
else{
    cell.backgroundColor = [UIColor greenColor];
}

这篇关于单击时的UItableViewCell背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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