Skip to content

Instantly share code, notes, and snippets.

@asmallteapot
Created February 5, 2012 19:59
Show Gist options
  • Select an option

  • Save asmallteapot/1747711 to your computer and use it in GitHub Desktop.

Select an option

Save asmallteapot/1747711 to your computer and use it in GitHub Desktop.
Less-hacky approach for configuring table views that are mostly static, but have some sections/cells that are conditionally visible.
// in -viewDidLoad
self.cellOrder = [NSMutableArray arrayWithObjects:@"Address", @"Hours", @"Call", @"Get Directions", nil];
if (foo) {
[self.cellOrder removeObject:@"Hours"];
}
if (!self.location.phoneNumber) {
[self.cellOrder removeObject:@"Call"];
}
// in data source & delegate methods
NSString *cellName = [self.cellOrder objectAtIndex:indexPath.row];
if ([cellName isEqualToString:@"Hours"]) {
// do something
} else if ([cellName isEqualToString:@"Call"]) {
// do something else
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment