Code:
// replace your cellForRowAtIndexPath with this one
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell = [self getCellContentView:CellIdentifier:indexPath.row];
return cell;
}
// add this function to your code
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier:(int)cellIndex {
// make sure your height below matches your cell height set
// or your cells will not be lined up with the color
CGRect CellFrame = CGRectMake(0, 0, 320, 60);
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
// put a UIView underneath for coloring
UIView * view = [[UIView alloc] initWithFrame:CellFrame];
if ( cellIndex%2 == 0 ){
// edit your cell color below
view.backgroundColor = [UIColor whiteColor];
}else{
// edit cell color 2 below
view.backgroundColor = [UIColor colorWithRed:.238 green:.238 blue:0.238 alpha:.10];
}
[cell.contentView addSubview:view];
[view release];
return cell;
}
///// this template will allow you to color every other cell a different color if desired replace your cellForRowAtIndexPath ... and add the cellIdentifier function