- Right click the blue icon in Xcode.
- Add new file > Cocoa Touch Classes > UIViewController subclass.
- Select all 3 checkbox options (Targetted for iPad, UITableViewController subclass, with XIB for user interface) (You could rearrange the file in correct locations under classes and resources).
- Open NewView.h. Add NSArray variable for populating the UITableView.
- Open NewView.m. Edit numberOfSectionsInTableView, numberOfRowsInSectioncellForRowAtIndexPath to populate the table form the NSArray variable.
- Open RootViewController.h. Add #import "NewView.h".
- Open RootViewController.m. Edit
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NewView * NewView = [[NewView alloc] initWithNibName:@"NewView" bundle:nil];
NewView.arrData = [[dataHolder objectAtIndex:indexPath.row] objectForKey:@"subdata"];
[[NewView navigationItem] setTitle: @"Subdata"];
[self.navigationController pushViewController:NewView animated:YES];
[NewView release];
/* When a row is selected, set the detail view controller's detail item to the item associated with the selected row.*/
detailViewController.detailItem = [dataHolder objectAtIndex:indexPath.row];
}
Save and Run.
When an item is selected from the main root view, the table will slide to left to give way to your new view, with a back button. If the RootViewController is given a title, the title will be used for the back button.
To provide a title:
Open RootViewController.m In viewDidLoad, add
[self.navigationItem setTitle: @"Main View"];