Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
I just create a UICollectionView, but when I set cell color, I got a strange result, can you tell me why?
Code:
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
    static NSString *kCellID = @"Cell";
    WordCell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
    
    cell.label.text = [NSString stringWithFormat:@"%i%i", indexPath.section, indexPath.row];

   switch (indexPath.row) {
        case 0:
        case 1:
        case 4:
        case 5:
            cell.backgroundColor = [UIColor greenColor];
            break;
            
        case 2:
        case 3:
        case 6:
            cell.backgroundColor = [UIColor redColor];
            break;

        default:
            break;
    }
    
    return cell;
}
 

Attachments

  • Screen Shot 2012-11-08 at 21.03.44.jpg
    Screen Shot 2012-11-08 at 21.03.44.jpg
    16.1 KB · Views: 1,590
  • Screen Shot 2012-11-08 at 21.04.59.jpg
    Screen Shot 2012-11-08 at 21.04.59.jpg
    15.6 KB · Views: 1,597
The line of red color is not on the same position with line of black cell, can you view?

Well, I can see that the whole table is moved upwards by 1-2 pixels. I presumed that's just because of the way you have taken the screenshot? I can't see anything in the code you have posted that would cause the position of the UICollectionView to change.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.