-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHistoryItem.m
184 lines (153 loc) · 5.46 KB
/
HistoryItem.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
// HistoryItem.m
// Allowance
//
// Created by Pablo Collins on 4/20/11.
//
#import "HistoryItem.h"
#import "TableViewSection.h"
#import "TableViewRow.h"
#import "ModelManager.h"
@implementation HistoryItem
@synthesize tableView, transaction, myIndexPath;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (!self) return nil;
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
tableData = [[TableViewData alloc] init];
TableViewSection *section = [[TableViewSection alloc] initWithTitle:@"Transaction Details"];
[tableData addSection:section];
TableViewRow *row = [[TableViewRow alloc] init];
row.cellMaker = ^{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:nil];
cell.textLabel.text = @"Type";
cell.detailTextLabel.text = transaction.tag;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
};
[section addRow:row];
row = [[TableViewRow alloc] init];
row.cellMaker = ^{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:nil];
cell.textLabel.text = @"Amount";
cell.detailTextLabel.text = [transaction formattedAmount];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
};
[section addRow:row];
row = [[TableViewRow alloc] init];
row.cellMaker = ^{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:nil];
cell.textLabel.text = @"Date";
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateStyle:NSDateFormatterMediumStyle];
NSString *dateString = [f stringFromDate:transaction.transactionDate];
cell.detailTextLabel.text = dateString;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
};
[section addRow:row];
section = [[TableViewSection alloc] initWithTitle:@"Notes"];
[tableData addSection:section];
row = [[TableViewRow alloc] init];
row.cellMaker = ^{
notesCell = [[EditableCell alloc] initWithStyle:UITableViewCellStyleValue2 placeholder:nil];
[notesCell.textLabel setText:transaction.notes];
[notesCell setTextViewDelegate:self];
return (UITableViewCell *)notesCell;
};
row.height = 85;
[section addRow:row];
}
- (void)viewDidUnload
{
[super viewDidUnload];
NSLog(@"viewDidUnload");
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillDisappear:(BOOL)animated
{
transaction.notes = [notesCell.textLabel text];
[[ModelManager sharedInstance] save];
[accountHistoryController.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:myIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
// pragma stuffs
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData numberOfRowsInSection:section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [tableData rowAtIndexPath:indexPath].cellMaker();
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat f = [tableData rowAtIndexPath:indexPath].height;
return f ? f : 44;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [tableData numberOfSections];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [tableData titleForHeaderInSection:section];
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
return [tableData titleForFooterInSection:section];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
return;
}
- (void)doneTouched:(id)sender
{
NSLog(@"doneTouched");
[notesCell hideKeyboard];
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect fr = self.view.frame;
fr.origin.y = -120;
self.view.frame = fr;
[UIView commitAnimations];
//self.navigationController.navigationBar s
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneTouched:)];
[self.navigationItem setRightBarButtonItem:doneBtn animated:YES];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
[self.navigationItem setRightBarButtonItem:nil animated:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect fr = self.view.frame;
fr.origin.y = 0;
self.view.frame = fr;
[UIView commitAnimations];
}
- (void)setAccountHistoryController:(AccountHistory *)ahc
{
accountHistoryController = ahc;
}
@end