-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListViewController.m
179 lines (144 loc) · 5.32 KB
/
ListViewController.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
//
// ListViewController.m
// AvocadoTest1
//
// Created by Jake on 12-04-19.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "ListViewController.h"
#import "ListRenderer.h"
#import "ExpandableCell.h"
#import "ShinyMenuItemViewController.h"
#import "ShinyOrderItemViewController.h"
#import "ShinyMenuComboViewController.h"
#import "ShinyComboItemViewController.h"
#import "ShinyOrderComboViewController.h"
#import "ShinyItemGroupViewController.h"
#import "ShinyOrderSummaryViewController.h"
#import "ShinyChoiceCell.h"
#import "ShinyItemFavoriteCell.h"
#import "ShinyComboFavoriteCell.h"
#import "Item.h"
#import "Menu.h"
#import "ItemGroup.h"
#import "Choice.h"
#import "Combo.h"
#import "AppData.h"
@implementation ListViewController
-(id)init
{
self = [super initWithNibName:nil bundle:nil];
if (self)
{
theTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain];
[theTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[theTableView setBackgroundColor:[UIColor whiteColor]];
[theTableView setDelegate:self];
}
return self;
}
-(void)viewDidAppear:(BOOL)animated
{
[[[self navigationController] navigationBar] setBackgroundImage:[UIImage imageNamed:@"BlankTopbarWithShadow.png"] forBarMetrics:UIBarMetricsDefault];
UILabel *toolbarText = [[UILabel alloc] initWithFrame:CGRectMake(
([[[self navigationController] navigationBar] frame ].size.width - 300) / 2,
(44 - 30) / 2,
300,
30)];
[toolbarText setFont:[UIFont fontWithName:@"Optima-ExtraBlack" size:22]];
[toolbarText setTextColor:[UIColor whiteColor]];
[toolbarText setBackgroundColor:[UIColor clearColor]];
[toolbarText setTextAlignment:UITextAlignmentCenter];
[[self navigationItem] setTitleView:toolbarText];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.0f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellClassName = [CustomViewCell cellIdentifierForData:[renderer objectForCellAtIndex:indexPath]];
SEL aSelector = NSSelectorFromString([NSString stringWithFormat:@"%@%@",cellClassName,@"Handler:"]);
if ([self respondsToSelector:aSelector]) {
[self performSelector:aSelector withObject:indexPath];
}
if ([[tableView cellForRowAtIndexPath:indexPath] isKindOfClass:[ExpandableCell class]])
{
[(ExpandableCell *)[tableView cellForRowAtIndexPath:indexPath] toggleOpen:indexPath :tableView];
}
}
-(void)ShinyMenuItemCellHandler:(NSIndexPath *) indexPath
{
//Override in the subclass.
}
-(void)ShinyOrderItemCellHandler:(NSIndexPath *)indexPath
{
//Override in the subclass.
}
-(void)ShinyComboOrderItemCellHandler:(NSIndexPath *) indexPath
{
Item *theItem = [[renderer objectForCellAtIndex:indexPath] objectForKey:@"orderComboItem"];
ShinyComboItemViewController *newController = [[ShinyComboItemViewController alloc] initWithItem:theItem];
[[self navigationController] pushViewController:newController animated:YES];
}
-(void)ShinyMenuComboCellHandler:(NSIndexPath *) indexPath
{
//Override in subclass
}
-(void)ShinyOrderComboCellHandler:(NSIndexPath *) indexPath
{
//Override in subclass
}
-(void)ShinyChoiceCellHandler:(NSIndexPath *)indexPath
{
Choice *theChoice = [[renderer objectForCellAtIndex:indexPath] objectForKey:@"choice"];
[theChoice toggleSelected];
[(ShinyChoiceCell *)[theTableView cellForRowAtIndexPath:indexPath] pulseView];
}
-(void)ShinyItemGroupCellHandler:(NSIndexPath *)indexPath
{
}
-(void)ShinyItemFavoriteCellHandler:(NSIndexPath *)indexPath
{
[(ShinyItemFavoriteCell *)[theTableView cellForRowAtIndexPath:indexPath] wasClicked];
}
-(void)ShinySettingsCellHandler:(NSIndexPath *)indexPath
{
//Do nothing, the subclass is the better guy to deal with this.
}
-(void)ShinyComboFavoriteCellHandler:(NSIndexPath *)indexPath
{
[(ShinyComboFavoriteCell *)[theTableView cellForRowAtIndexPath:indexPath] wasClicked];
}
-(void)ShinyOrderHistoryCellHandler:(NSIndexPath *)indexPath
{
Order *theOrder = [[renderer objectForCellAtIndex:indexPath] objectForKey:@"historicalOrder"];
ShinyOrderSummaryViewController *newController = [[ShinyOrderSummaryViewController alloc] initWithOrder:theOrder];
[[self navigationController] pushViewController:newController animated:YES];
}
-(void)ShinyDeleteCellHandler:(NSIndexPath *)indexPath
{
//This should be dealt with by the subclass
}
-(void)ShinyPaymentViewCellHandler:(NSIndexPath *)indexPath
{
//This one too.
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [CustomViewCell cellHeightForData:[renderer objectForCellAtIndex:indexPath]];
}
-(void)loadView
{
[super loadView];
[self setView:theTableView];
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end