Note that there are some explanatory texts on larger screens.

plurals
  1. POGrouped Table View Obj-C
    text
    copied!<p>I followed the tutorial <a href="http://gigaom.com/apple/iphone-dev-sessions-create-a-navigation-based-application/" rel="nofollow">here</a> and was wondering how to make the table appear grouped.</p> <p>ex:</p> <p>group1 contains Subview One and Subview Two</p> <p>group2 contains Subview Three</p> <p>I switched the type in interface builder but that only shows one group.</p> <p>Thanks, Adam</p> <p>Sidenote* I am a completely new at objective c, hence the tutorial.</p> <p><strong>EDIT</strong></p> <p>I thought it might be helpful to put up the piece of code</p> <pre><code>#import "RootViewController.h" #import "SubViewOneController.h" #import "SubViewTwoController.h" @implementation RootViewController #pragma mark - #pragma mark View lifecycle -(void)awakeFromNib { views = [[NSMutableArray alloc] init]; SubViewOneController *subViewOneController = [[SubViewOneController alloc] init]; SubViewTwoController *subViewTwoController = [[SubViewTwoController alloc] init]; //Subview 1 subViewOneController.title = @"Subview One"; [views addObject:[NSDictionary dictionaryWithObjectsAndKeys: @"Subview One", @"title", subViewOneController, @"controller", nil]]; [subViewOneController release]; //Subview 2 subViewOneController = [[SubViewOneController alloc] init]; subViewOneController.title = @"Subview Two"; [views addObject:[NSDictionary dictionaryWithObjectsAndKeys: @"Subview Two", @"title", subViewTwoController, @"controller", nil]]; [subViewOneController release]; //Subview 3 subViewOneController = [[SubViewOneController alloc] init]; subViewOneController.title = @"Subview Three"; [views addObject:[NSDictionary dictionaryWithObjectsAndKeys: @"Subview Three", @"title", subViewOneController, @"controller", nil]]; [subViewOneController release]; UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init]; temporaryBarButtonItem.title = @"Back"; self.navigationItem.backBarButtonItem = temporaryBarButtonItem; [temporaryBarButtonItem release]; self.title = @"Basic Navigation"; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [views count]; } // //I think it goes somewhere in here // - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:CellIdentifier]; } cell.text = [[views objectAtIndex:indexPath.row] objectForKey:@"title"]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UIViewController *targetViewController = [[views objectAtIndex:indexPath.row] objectForKey:@"controller"]; [[self navigationController] pushViewController:targetViewController animated:YES]; } - (void)dealloc { [views dealloc]; [super dealloc]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload