forked from lukeredpath/LRTableModel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamplesIndexViewController.m
More file actions
100 lines (77 loc) · 2.64 KB
/
ExamplesIndexViewController.m
File metadata and controls
100 lines (77 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// ExamplesIndexViewController.m
// TableViewModel
//
// Created by Luke Redpath on 10/08/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//
#import "ExamplesIndexViewController.h"
#import "LRTableModelEvent.h"
@implementation ExamplesTableModel
- (id)initWithCellProvider:(id <LRTableModelCellProvider>)theCellProvider
{
if (self = [super initWithCellProvider:theCellProvider]) {
examples = [[NSMutableArray alloc] init];
}
return self;
}
- (void)loadExamplesFromPlistNamed:(NSString *)plistName inBundle:(NSBundle *)bundle
{
examples = [NSArray arrayWithContentsOfFile:[bundle pathForResource:plistName ofType:@"plist"]];
[self notifyListeners:[LRTableModelEvent refreshedData]];
}
- (NSInteger)numberOfSections;
{
return 1;
}
- (NSInteger)numberOfRowsInSection:(NSInteger)sectionIndex;
{
return [examples count];
}
- (id)objectAtIndexPath:(NSIndexPath *)indexPath;
{
return [examples objectAtIndex:indexPath.row];
}
@end
@implementation ExamplesIndexViewController
- (ExamplesTableModel *)examplesTableModel
{
if (examplesTableModel == nil) {
examplesTableModel = [[ExamplesTableModel alloc] initWithCellProvider:self];
[examplesTableModel addTableModelListener:self];
}
return examplesTableModel;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.rowHeight = 65;
self.tableView.dataSource = self.examplesTableModel;
[self.examplesTableModel loadExamplesFromPlistNamed:@"Examples" inBundle:[NSBundle mainBundle]];
}
#pragma mark -
#pragma mark LRTableModel methods
- (void)tableModelChanged:(LRTableModelEvent *)changeEvent
{
[self.tableView reloadData];
}
- (UITableViewCell *)cellForObjectAtIndexPath:(NSIndexPath *)indexPath reuseIdentifier:(NSString *)reuseIdentifier
{
return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
}
- (void)configureCell:(UITableViewCell *)cell forObject:(id)object atIndexPath:(NSIndexPath *)indexPath
{
cell.textLabel.text = [object valueForKey:@"name"];
cell.detailTextLabel.text = [object valueForKey:@"description"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
#pragma mark -
#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *exampleData = [self.examplesTableModel objectAtIndexPath:indexPath];
UIViewController *exampleViewController = [[NSClassFromString([exampleData valueForKey:@"controller"]) alloc] init];
exampleViewController.title = [exampleData valueForKey:@"name"];
[self.navigationController pushViewController:exampleViewController animated:YES];
}
@end