Skip to content

Instantly share code, notes, and snippets.

@beelsebob
Created October 10, 2012 09:16
Show Gist options
  • Select an option

  • Save beelsebob/3864297 to your computer and use it in GitHub Desktop.

Select an option

Save beelsebob/3864297 to your computer and use it in GitHub Desktop.
- (void)viewDidLoad
{
[super viewDidLoad];
[self setTableView:[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]];
[self setRegions:@[@[@"Bologna", @"Florence", @"Milan"]], @[@"Naples", @"Rome", @"Turin"]]];
[self setTitle:@"Region"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self regions][section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[[cell textLabel] setText:[self regions][[indexPath section]][[indexPath row]]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CityController *cityController = [[CityController alloc] initWithNibName:@"CityController" bundle:nil];
[cityController setCity:[self regions][[indexPath section]][[indexPath row]]];
[[self navigationController] pushViewController:cityController animated:YES];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment