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

 

 

 

posted @ 2013-05-20 19:58  cocoajin  阅读(505)  评论(0编辑  收藏  举报