This example shows how to create a standard UITableViewController using a static Nimbus NITableViewModel instead of implementing the data source methods by hand.
@interface ExampleTableViewController : UITableViewController <
@private
}
@end
@implementation CatalogTableViewController
- (void)dealloc {
NI_RELEASE_SAFELY(_model);
[super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
NSArray* tableContents =
[NSArray arrayWithObjects:
@"Section 1",
[NSDictionary dictionaryWithObject:@"Row 1" forKey:@"title"],
[NSDictionary dictionaryWithObject:@"Row 2" forKey:@"title"],
[NSDictionary dictionaryWithObject:@"Row 3" forKey:@"title"],
@"Section 2",
[NSDictionary dictionaryWithObject:@"Row 4" forKey:@"title"],
nil];
delegate:self];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.dataSource = _model;
}
cellForTableView: (UITableView *)tableView
atIndexPath: (NSIndexPath *)indexPath
withObject: (id)object {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"row"];
if (nil == cell) {
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
reuseIdentifier: @"row"]
autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = [object objectForKey:@"title"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
id object = [_model objectAtIndexPath:indexPath];
}
@end