Skip to content

Instantly share code, notes, and snippets.

@romyilano
Created February 23, 2013 07:02
Show Gist options
  • Select an option

  • Save romyilano/5018770 to your computer and use it in GitHub Desktop.

Select an option

Save romyilano/5018770 to your computer and use it in GitHub Desktop.
creating alternating cell types
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier;
// nice! make the conditional here
if ((indexPath.row %2) == 0 ) {
CellIdentifier = @"rowOdd";
} else {
CellIdentifier = @"rowEven";
}
}
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
switch ([CellIdentifier isEqualToString:@"rowOdd"]) {
case YES:
cell = [[UITableViewCell alloc]
initWithStyle:UITableVIewCellStyleDefault
reuseIdentifier:cellIdentifier];
break;
case NO:
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:cellIdentifer];
break;
default:
break:
}
}
cell.textLabel.text = @"textLabel";
cell.detailTextLabel.text =@"detailTextLabel";
}
}
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment