zoukankan      html  css  js  c++  java
  • UITableViewCell隔行换颜色

    1:在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

      代理方法里面设置颜色转换逻辑;

    2:在-(void)viewDidAppear:(BOOL)animated 

      重新加载 tableview reloadData;

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
        static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
         
        }
        
       cell.textLable.text = @"hello";
        //Cell隔行换颜色;必须写上 else的颜色可能;
        if (indexPath.row %2 ==0) {
            cell.textLabel.backgroundColor = [UIColor grayColor];
            
        }else{
            cell.textLabel.backgroundColor = [UIColor yellowColor];
    
        }
    
        return cell;
    }
    
    //cell隔行换颜色,需在这里reloadData 一下;
    -(void)viewDidAppear:(BOOL)animated
    {
        [self.tableView reloadData];
    }
    View Code
  • 相关阅读:
    c++第十八章-(容器和算法)
    07表与表之间的关系
    06约束
    01 Hello World!
    05文件合并脚本--By Mark Lutz
    04文件分割器脚本
    05数据库用户操作
    03扫描模块搜索路径
    02扫描目录树
    01扫描单个目录
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3089308.html
Copyright © 2011-2022 走看看