UITableView 隔行换色 选中背景色 取消选中颜色 返回后显示正常颜色

 隔行换色

   UIView *view=[[UIViewalloc]initWithFrame:cell.frame];

    if (indexPath.row % 2==0) {

        view.backgroundColor=[UIColor blueColor];

    }

    else

    {

        view.backgroundColor=[UIColor whiteColor];

    }

    cell.backgroundView=view;

关于选中背景色的显示以及返回正常色

有两张实现方式 

1  .h 基于UIviewControl

   UIView *bgsele_view=[[UIView alloc]initWithFrame:cell.frame];

    bgsele_view.backgroundColor=[UIColor redColor];

    cell.selectedBackgroundView=bgsele_view;

取消选中颜色 返回后显示正常颜色  

tableView  的didSelectRowAtIndexPath的事件中加入

[tableviewdeselectRowAtIndexPath:[tableviewindexPathForSelectedRow] animated:YES];

2  .h 基于 UITableViewController的"界面" ,默认当推送到子"界面",然后返回主“界面”,选中的颜色会自动取消,无须再进行代码的编写

原文地址:https://www.cnblogs.com/Rampage/p/2425515.html