Skip to content

Instantly share code, notes, and snippets.

@mafis
Created June 29, 2010 08:29
Show Gist options
  • Save mafis/456968 to your computer and use it in GitHub Desktop.
Save mafis/456968 to your computer and use it in GitHub Desktop.
//Methode zum berechnen der absoluten Position
- (NSInteger)realRowNumberForIndexPath:(NSIndexPath *)indexPath inTableView:(UITableView *)tableView
{
NSInteger retInt = 0;
if (!indexPath.section)
{
return indexPath.row;
}
for (int i=0; i<indexPath.section;i++)
{
retInt += [tableView numberOfRowsInSection:i];
}
return retInt + indexPath.row;
}
//Anwendungsbeispiel
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
//Absolute Position der aktuellen UITableViewCell zurückbekommen
NSInteger realRow = [self realRowNumberForIndexPath:indexPath inTableView:tableView];
//Wenn die absolute Position durch 2 Teilbar ist, wird der Hintergrund lightGrayColor, ansonsten wird sie DunkelGrau
cell.backgroundColor = (realRow%2)?[UIColor lightGrayColor]:[UIColor grayColor];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment