/ Published in: iPhone
Pulls data from a plist set up as a dictionary of arrays of strings.
Creates multi-level TableView that can be nested inside a navigation controller.
Snippet shows key methods for 2 nested levels.
2 levels --> 2 classes (both of which extend UITableViewController)
Creates multi-level TableView that can be nested inside a navigation controller.
Snippet shows key methods for 2 nested levels.
2 levels --> 2 classes (both of which extend UITableViewController)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// ---------- Top Level ---------------- - (void)viewDidLoad { self.title = @"Categories"; ofType:@"plist"]; initWithContentsOfFile:path]; self.buildings = dict; [dict release]; for(id name in buildings) { CategorySecondLevelViewController *controller = [[CategorySecondLevelViewController alloc] initWithStyle:UITableViewStylePlain]; controller.title = name; [array addObject:controller]; [controller release]; } self.categories = array; [array release]; [super viewDidLoad]; } - (UITableViewCell *)tableView:(UITableView *)tableView // reuse cell if possible UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CategoryCell]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CategoryCell] autorelease]; } // configure cell NSUInteger row = [indexPath row]; // extension point to include images if wanted UITableViewController *controller = [categories objectAtIndex:row]; cell.textLabel.text = controller.title; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } // ---------- Second Level ---------------- - (void)viewDidLoad { ofType:@"plist"]; initWithContentsOfFile:path]; self.list = values; [dict release]; [super viewDidLoad]; } - (UITableViewCell *)tableView:(UITableView *)tableView UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: BuildingIdentifier]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:BuildingIdentifier] autorelease]; } NSUInteger row = [indexPath row]; cell.textLabel.text = [list objectAtIndex:row]; return cell; }