-
Notifications
You must be signed in to change notification settings - Fork 0
/
KidsTable.m
100 lines (83 loc) · 3.35 KB
/
KidsTable.m
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
//
// KidsTable.m
// Allowance
//
// Created by Pablo Collins on 6/10/10.
//
#import "KidsTable.h"
@implementation KidsTable
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self readAndReload];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [self addButton];
self.navigationItem.leftBarButtonItem = [self settingsButton];
[self readKids];
}
- (UIBarButtonItem *)settingsButton {
if (settingsButton == nil) {
settingsButton = [[UIBarButtonItem alloc] initWithTitle:@"Settings"
style:UIBarButtonItemStylePlain
target:self
action:@selector(pushedSettings:)];
}
return settingsButton;
}
- (UIBarButtonItem *)addButton {
if (addButton == nil) {
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(pushedAdd:)];
}
return addButton;
}
- (void)pushedAdd:(id)sender {
NewKidForm *kidForm = [[NewKidForm alloc] initWithNibName:@"KidForm" bundle:nil];
kidForm.opener = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:kidForm];
[self presentModalViewController:navController animated:YES];
}
- (void)pushedSettings:(id)sender {
SettingsEditor *settingsEditor = [[SettingsEditor alloc] initWithNibName:@"SettingsEditor" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:settingsEditor];
settingsEditor.opener = self;
[self presentModalViewController:navController animated:YES];
}
- (void)readKids {
kids = [[ModelManager sharedInstance] findAll:@"Kid"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [kids count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CellID";
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
NSUInteger i = [indexPath indexAtPosition:1];
Kid *kid = [kids objectAtIndex:i];
cell.textLabel.text = kid.name;
cell.detailTextLabel.text = [kid balanceString];
return cell;
}
- (void)dismissModalEditor {
[self dismissModalViewControllerAnimated:YES];
[self readAndReload];
}
- (void)readAndReload {
[self readKids];
[((UITableView *)self.view) reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
KidDetail *kidDetail = [[KidDetail alloc] initWithNibName:@"KidDetail" bundle:nil];
kidDetail.kidsTable = self;
Kid *kid = [kids objectAtIndex:[indexPath indexAtPosition:1]];
[AllowanceAppDelegate setCurrentKid:kid];
[self.navigationController pushViewController:kidDetail animated:YES];
}
@end