This is my first IOS app and when i try to set the cell background colors to alternate they work fine when i scroll slowly, but when i try to scroll fast the colors mingle: inst
You need to add an else statement to set the background color to white. Because of cell reuse, as soon as a cell's background is set to gray, it will never get set back to white back when reused for a row that isn't row % 2. Like so:
if(indexPath.row % 2){
cell.backgroundColor = [UIColor colorWithRed:242/255.0 green:243/255.0 blue:250/255.0 alpha:1.0];
} else {
cell.backgroundColor = [UIColor whiteColor];
}
The reason is that you are not dealing with the fact that cells are reused. You are providing instructions for half the cases:
if(indexPath.row % 2){
cell.backgroundColor = [UIColor colorWithRed:242/255.0 green:243/255.0 blue:250/255.0 alpha:1.0];
}
But you are not saying what to do in the other half of the cases.
This has nothing to do with speed of scrolling. It's just that the very same cell that you previous set to gray will later be used in a row that you want to be white. So you need to set it to white, or it will still be gray from its previous use. This is true of every aspect of a cell.