Setting background color of a table view cell on iPhone

后端 未结 12 712
孤街浪徒
孤街浪徒 2020-12-02 11:23

I want to achieve the effect where one cell of the table view will have blue background, the next one will have white, the next one will have blue again, and then white and

12条回答
  •  独厮守ぢ
    2020-12-02 12:02

    //time saving method:

    //in cell for index method:

    static NSString* evenIdentifier = @"even";
    static NSString* oddIdentifier = @"odd";
    
    __weak identifier;
    if(indexPath.row %2 ==0)
    {
        identifier = evenIdentifier;
    }else{
        identifier = oddIdentifier;
    }
    
    cell = dequeue..WithIdentifier: identifier;
    if(cell == nil){
        cell = allocOrLoadNib...;
        cell.backgroundColor = (indexPath.row %2 ==0 ? evenColor : oddColor);
    }
    

    // change the cell content and then return it. Easy job.

    // this is a outline code. Please not copy it directly.

提交回复
热议问题