-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPlayersViewController.m
338 lines (315 loc) · 10.6 KB
/
PlayersViewController.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
//
// PlayersViewController.m
// Scorekeeper Beta
//
// Created by Ali ElSayed on 11/12/12.
// Copyright (c) 2012 Ali ElSayed. All rights reserved.
//
//#import "PlayersViewController.h"
#import "PlayersViewController.h"
@interface PlayersViewController ()
@end
@implementation PlayersViewController
@synthesize homeTeamTableView = _homeTeamTableView;
@synthesize awayTeamTableView = _awayTeamTableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//homeTeamTableView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
//awayTeamTableView.backgroundColor = [UIColor colorWithRed:0.55 green:0.55 blue:0.55 alpha:1];
statsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"statsViewController"];
// Send data
[statsViewController sportName: sportName];
//if (homeTeam.count < 11 && awayTeam.count < 11) {
//self.homeTeamTableView.scrollEnabled = NO;
//self.awayTeamTableView.scrollEnabled = NO;
//}
self.homeTeamTableView.backgroundColor = [UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:1.0];
self.awayTeamTableView.backgroundColor = [UIColor colorWithRed:0.94 green:0.94 blue:0.94 alpha:1.0];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; // There is one section in both home/away team tables
}
// Number of rows in a table depends on the table that's calling the function
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == [self homeTeamTableView]) // If it's the home team's table
{
return homeTeam.count; // Return the home team array size (which contains the number of home players)
}
else // Otherwise,
{
return awayTeam.count; // Return the away team array size
}
//if (homeTeam.count >= awayTeam.count) // Create equal number of cells for both teams regardless of how many players they have
//{
// return homeTeam.count;
//}
//else
//{
// return awayTeam.count;
//}
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(TeamPlayerCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
//if (tableView == self.homeTeamTableView) {
// cell.backgroundColor = (indexPath.row % 2) ? [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]:[UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.0];
//} else {
//cell.backgroundColor = (indexPath.row % 2) ? [UIColor colorWithRed:0.93 green:0.93 blue:0.93 alpha:1.0]:[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:1.0];
//}
//if (tableView == self.homeTeamTableView) {
CGFloat var, diff;
// diff = 0.1
// soccer var = 0.025
// var 0.05 (else)
// color r = 0.65 g = 0.65 b = 0.65
if (tableView == self.homeTeamTableView) {
diff = 0;
} else {
diff = 0.01;
}
if (sportName == @"Soccer" && (homeTeam.count > 5 || awayTeam.count > 5))
{
var = 0.01 * indexPath.row + diff;
}
else
{
var = 0.02 * indexPath.row + diff;
}
cell.backgroundColor = [UIColor colorWithRed:0.88 + var green:0.88 + var blue:0.88 + var alpha:1.0];
cell.playerNameLabel.textColor = [UIColor colorWithRed:0.32 + var green:0.32 + var blue:0.32 + var alpha:1.0];
cell.jerseyNumberLabel.textColor = [UIColor colorWithRed:0.32 + var green:0.32 + var blue:0.32 + var alpha:1.0];
/*}
else
{
CGFloat var;
if (sportName == @"Soccer" && (homeTeam.count > 5 || awayTeam.count > 5))
var = 0.025 * indexPath.row;
else
var = 0.05 * indexPath.row;
cell.backgroundColor = [UIColor colorWithRed:0.75 + var green:0.75 + var blue:0.75 + var alpha:1.0];
cell.playerNameLabel.textColor = [UIColor colorWithRed:0.25 + var green:0.25 + var blue:0.25 + var alpha:1.0];
cell.jerseyNumberLabel.textColor = [UIColor colorWithRed:0.25 + var green:0.25 + var blue:0.25 + var alpha:1.0];
}*/
}
// Set the header height!
//- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//
//}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//return 33;
CGRect bounds = [[UIScreen mainScreen] bounds];
if (bounds.size.height == 568) {
return 455/11; // which is 41.3636363636...
}
else if(bounds.size.height == 480)
{
return 33;
}
return 33;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Apple says I should do this :p
[tableView deselectRowAtIndexPath:indexPath animated:NO];
//View code here
/*if (tableView == [self homeTeamTableView]) // self is needed there
{
if (sportName == @"Soccer")
{
statsViewController.soccerPlayer = [homeTeam objectAtIndex:indexPath.row];
}
}
else
{
if (sportName == @"Soccer")
{
statsViewController.soccerPlayer = [awayTeam objectAtIndex:indexPath.row];
}
}*/
if (sportName == @"Soccer")
{
if (tableView == [self homeTeamTableView])
{
statsViewController.soccerPlayer = [homeTeam objectAtIndex:indexPath.row];
}
else
{
statsViewController.soccerPlayer = [awayTeam objectAtIndex:indexPath.row];
}
}
else if (sportName == @"Basketball")
{
if (tableView == [self homeTeamTableView])
{
statsViewController.basketballPlayer = [homeTeam objectAtIndex:indexPath.row];
}
else
{
statsViewController.basketballPlayer = [awayTeam objectAtIndex:indexPath.row];
}
}
statsViewController.homeTeamScoreLabel = self.homeTeamScoreLabel; // Pass the score label
statsViewController.awayTeamScoreLabel = self.awayTeamScoreLabel; // Pass the score label
[statsViewController sportName: self.sportName];
//statsViewController.gameController = self.gameController;
// Animate to the next view
// with
// a
// cool
// custom
// animation!
[self presentSemiViewController:statsViewController withOptions: @{KNSemiModalOptionKeys.animationDuration: @(0.25)}];
}
- (void) setPlayerCell: (TeamPlayerCell*) cell for: (UITableView*) tableView at: (NSIndexPath*) indexPath
{
if (sportName == @"Soccer")
{
SoccerPlayer *player;
if (tableView == [self homeTeamTableView]) // self is needed there
{
if (indexPath.row < homeTeam.count)
player = [homeTeam objectAtIndex:[indexPath row]];
}
else
{
if (indexPath.row < awayTeam.count)
player = [awayTeam objectAtIndex:[indexPath row]];
}
// configure cell here...
// If the player has a number but no number (0), then but a dash near his/her name.
if (player.jerseyNumber == 0) // If the player jersey number is 0, then
{
if (player.name.length > 0)
{
cell.jerseyNumberLabel.text = @"-"; // place a dash instead
}
else
{
cell.jerseyNumberLabel.text = @"";
}
}
else
{
cell.jerseyNumberLabel.text = [NSString stringWithFormat:@"%i", player.jerseyNumber];
}
cell.playerNameLabel.text = player.name;
}
else if (sportName == @"Basketball")
{
BasketballPlayer *player;
if (tableView == [self homeTeamTableView]) // self is needed there
{
if (indexPath.row < homeTeam.count)
player = [homeTeam objectAtIndex:[indexPath row]];
}
else
{
if (indexPath.row < awayTeam.count)
player = [awayTeam objectAtIndex:[indexPath row]];
}
// configure cell here...
if (player.jerseyNumber == 0) // If the player jersey number is 0, then
{
if (player.name.length > 0)
{
cell.jerseyNumberLabel.text = @"-"; // place a dash instead
}
else
{
cell.jerseyNumberLabel.text = @"";
}
}
else
{
cell.jerseyNumberLabel.text = [NSString stringWithFormat:@"%i", player.jerseyNumber];
}
cell.playerNameLabel.text = player.name;
}
}
// Add cells to the right table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"playerCell";
TeamPlayerCell *cell = (TeamPlayerCell*) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[TeamPlayerCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:cellIdentifier];
}
/*SoccerPlayer *player;
if (tableView == [self homeTeamTableView]) // self is needed there
{
if (indexPath.row < homeTeam.count)
player = [homeTeam objectAtIndex:[indexPath row]];
}
else
{
if (indexPath.row < awayTeam.count)
player = [awayTeam objectAtIndex:[indexPath row]];
}
// configure cell here...
// If the player has a number but no number (0), then but a dash near his/her name.
if (player.jerseyNumber == 0) // If the player jersey number is 0, then
{
if (player.name.length > 0)
{
cell.jerseyNumberLabel.text = @"-"; // place a dash instead
}
else
{
cell.jerseyNumberLabel.text = @"";
}
}
else
{
cell.jerseyNumberLabel.text = [NSString stringWithFormat:@"%i", player.jerseyNumber];
}
cell.playerNameLabel.text = player.name;*/
[self setPlayerCell: cell for: tableView at: indexPath];
return cell;
}
- (NSMutableArray*) homeTeam
{
return homeTeam;
}
- (NSMutableArray*) awayTeam
{
return awayTeam;
}
- (NSString*) sportName
{
return sportName;
}
- (id) homeTeam: (NSMutableArray*) _homeTeam
{
homeTeam = _homeTeam;
return self;
}
- (id) awayTeam: (NSMutableArray*) _awayTeam
{
awayTeam = _awayTeam;
return self;
}
- (id) sportName:(NSString *)_sportName
{
sportName = _sportName;
return self;
}
@end