-
Notifications
You must be signed in to change notification settings - Fork 25
/
PersonalInfoViewController.m
1243 lines (1075 loc) · 40 KB
/
PersonalInfoViewController.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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** Cycle Philly, 2013 Code For Philly
* Philadelphia, PA. USA
*
*
* Contact: Corey Acri <acri.corey@gmail.com>
* Lloyd Emelle <lemelle@codeforamerica.org>
*
* Updated/Modified for Philadelphia's app deployment. Based on the
* Cycle Atlanta and CycleTracks codebase for SFCTA.
*
* Cycle Atlanta, Copyright 2012, 2013 Georgia Institute of Technology
* Atlanta, GA. USA
*
* @author Christopher Le Dantec <ledantec@gatech.edu>
* @author Anhong Guo <guoanhong@gatech.edu>
*
* Updated/Modified for Atlanta's app deployment. Based on the
* CycleTracks codebase for SFCTA.
*
** CycleTracks, Copyright 2009,2010 San Francisco County Transportation Authority
* San Francisco, CA, USA
*
* @author Matt Paul <mattpaul@mopimp.com>
*
* This file is part of CycleTracks.
*
* CycleTracks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CycleTracks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CycleTracks. If not, see <http://www.gnu.org/licenses/>.
*/
//
// PersonalInfoViewController.m
// CycleTracks
//
// Copyright 2009-2010 SFCTA. All rights reserved.
// Written by Matt Paul <mattpaul@mopimp.com> on 9/23/09.
// For more information on the project,
// e-mail Billy Charlton at the SFCTA <billy.charlton@sfcta.org>
#import "PersonalInfoViewController.h"
#import "User.h"
#import "constants.h"
#define kMaxCyclingFreq 3
@implementation PersonalInfoViewController
@synthesize delegate, managedObjectContext, user;
@synthesize age, email, gender, ethnicity, income, homeZIP, workZIP, schoolZIP;
@synthesize cyclingFreq, riderType, riderHistory;
@synthesize ageSelectedRow, genderSelectedRow, ethnicitySelectedRow, incomeSelectedRow, cyclingFreqSelectedRow, riderTypeSelectedRow, riderHistorySelectedRow, selectedItem;
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if (self = [super initWithStyle:UITableViewStyleGrouped]) {
}
return self;
}
- (id)init
{
NSLog(@"INIT");
if (self = [super initWithStyle:UITableViewStyleGrouped]) {
}
return self;
}
- (id)initWithManagedObjectContext:(NSManagedObjectContext*)context
{
if (self = [super initWithStyle:UITableViewStyleGrouped]) {
NSLog(@"PersonalInfoViewController::initWithManagedObjectContext");
self.managedObjectContext = context;
}
return self;
}
- (UITextField*)initTextFieldAlpha
{
CGRect frame = CGRectMake( 152, 7, 138, 29 );
UITextField *textField = [[UITextField alloc] initWithFrame:frame];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.textAlignment = UITextAlignmentRight;
textField.placeholder = @"Choose one";
textField.delegate = self;
return textField;
}
- (UITextField*)initTextFieldBeta
{
CGRect frame = CGRectMake( 152, 7, 138, 29 );
UITextField *textField = [[UITextField alloc] initWithFrame:frame];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.textAlignment = UITextAlignmentRight;
textField.placeholder = @"Choose one";
textField.delegate = self;
return textField;
}
- (UITextField*)initTextFieldEmail
{
CGRect frame = CGRectMake( 152, 7, 138, 29 );
UITextField *textField = [[UITextField alloc] initWithFrame:frame];
textField.autocapitalizationType = UITextAutocapitalizationTypeNone,
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.textAlignment = UITextAlignmentRight;
textField.placeholder = @"name@domain";
textField.keyboardType = UIKeyboardTypeEmailAddress;
textField.returnKeyType = UIReturnKeyDone;
textField.delegate = self;
return textField;
}
- (UITextField*)initTextFieldNumeric
{
CGRect frame = CGRectMake( 152, 7, 138, 29 );
UITextField *textField = [[UITextField alloc] initWithFrame:frame];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.textAlignment = UITextAlignmentRight;
textField.placeholder = @"12345";
textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
textField.returnKeyType = UIReturnKeyDone;
textField.delegate = self;
return textField;
}
- (User *)createUser
{
// Create and configure a new instance of the User entity
User *noob = (User *)[[NSEntityDescription insertNewObjectForEntityForName:@"User" inManagedObjectContext:managedObjectContext] retain];
NSError *error;
if (![managedObjectContext save:&error]) {
// Handle the error.
NSLog(@"createUser error %@, %@", error, [error localizedDescription]);
}
return [noob autorelease];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Set the title.
// self.title = @"Personal Info";
genderArray = [[NSArray alloc]initWithObjects: @" ", @"Female",@"Male", nil];
ageArray = [[NSArray alloc]initWithObjects: @" ", @"Less than 18", @"18-24", @"25-34", @"35-44", @"45-54", @"55-64", @"65+", nil];
ethnicityArray = [[NSArray alloc]initWithObjects: @" ", @"White", @"African American", @"Asian", @"Native American", @"Pacific Islander", @"Multi-racial", @"Hispanic / Mexican / Latino", @"Other", nil];
incomeArray = [[NSArray alloc]initWithObjects: @" ", @"Less than $20,000", @"$20,000 to $39,999", @"$40,000 to $59,999", @"$60,000 to $74,999", @"$75,000 to $99,999", @"$100,000 or greater", nil];
cyclingFreqArray = [[NSArray alloc]initWithObjects: @" ", @"Less than once a month", @"Several times per month", @"Several times per week", @"Daily", nil];
riderTypeArray = [[NSArray alloc]initWithObjects: @" ", @"Strong & fearless", @"Enthused & confident", @"Comfortable, but cautious", @"Interested, but concerned", nil];
riderHistoryArray = [[NSArray alloc]initWithObjects: @" ", @"Since childhood", @"Several years", @"One year or less", @"Just trying it out / just started", nil];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; //as we want to display a subview we won't be using the default buttons but rather we're need to create a toolbar to display the buttons on
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[actionSheet setActionSheetStyle:UIActionSheetStyleAutomatic];
// initialize text fields
self.age = [self initTextFieldAlpha];
self.email = [self initTextFieldEmail];
self.gender = [self initTextFieldAlpha];
self.ethnicity = [self initTextFieldAlpha];
self.income = [self initTextFieldAlpha];
self.homeZIP = [self initTextFieldNumeric];
self.workZIP = [self initTextFieldNumeric];
self.schoolZIP = [self initTextFieldNumeric];
self.cyclingFreq = [self initTextFieldBeta];
self.riderType = [self initTextFieldBeta];
self.riderHistory =[self initTextFieldBeta];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
// Set up the buttons.
// this is actually the Save button.
UIBarButtonItem* done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(done)];
//Initial Save button state is disabled. will be enabled if a change has been made to any of the fields.
done.enabled = NO;
self.navigationItem.rightBarButtonItem = done;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSError *error;
NSInteger count = [managedObjectContext countForFetchRequest:request error:&error];
NSLog(@"saved user count = %ld", (long)count);
if ( count == 0 )
{
// create an empty User entity
[self setUser:[self createUser]];
}
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error.
NSLog(@"no saved user");
if ( error != nil )
NSLog(@"PersonalInfo viewDidLoad fetch error %@, %@", error, [error localizedDescription]);
}
[self setUser:[mutableFetchResults objectAtIndex:0]];
if ( user != nil )
{
// initialize text fields indexes to saved personal info
age.text = [ageArray objectAtIndex:[user.age integerValue]];
ageSelectedRow = [user.age integerValue];
email.text = user.email;
gender.text = [genderArray objectAtIndex:[user.gender integerValue]];;
genderSelectedRow = [user.gender integerValue];
ethnicity.text = [ethnicityArray objectAtIndex:[user.ethnicity integerValue]];
ethnicitySelectedRow= [user.ethnicity integerValue];
income.text = [incomeArray objectAtIndex:[user.income integerValue]];
incomeSelectedRow = [user.income integerValue];
homeZIP.text = user.homeZIP;
workZIP.text = user.workZIP;
schoolZIP.text = user.schoolZIP;
cyclingFreq.text = [cyclingFreqArray objectAtIndex:[user.cyclingFreq integerValue]];
cyclingFreqSelectedRow = [user.cyclingFreq integerValue];
riderType.text = [riderTypeArray objectAtIndex:[user.rider_type integerValue]];
riderTypeSelectedRow = [user.rider_type integerValue];
riderHistory.text = [riderHistoryArray objectAtIndex:[user.rider_history integerValue]];
riderHistorySelectedRow = [user.rider_history integerValue];
// init cycling frequency
//NSLog(@"init cycling freq: %d", [user.cyclingFreq intValue]);
//cyclingFreq = [NSNumber numberWithInt:[user.cyclingFreq intValue]];
//if ( !([user.cyclingFreq intValue] > kMaxCyclingFreq) )
// [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:[user.cyclingFreq integerValue]
// inSection:2]];
}
else
NSLog(@"init FAIL");
[mutableFetchResults release];
[request release];
}
#pragma mark UITextFieldDelegate methods
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if(currentTextField == email || currentTextField == workZIP || currentTextField == homeZIP || currentTextField == schoolZIP || textField != email || textField != workZIP || textField != homeZIP || textField != schoolZIP){
NSLog(@"currentTextField: text2");
[currentTextField resignFirstResponder];
[textField resignFirstResponder];
}
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)myTextField{
/*if(currentTextField == email || currentTextField == workZIP || currentTextField == homeZIP || currentTextField == schoolZIP){
NSLog(@"currentTextField: text");
[currentTextField resignFirstResponder];
[myTextField resignFirstResponder];
}
NSLog(@"currentTextfield: picker");*/
NSLog(@"beginedit");
currentTextField = myTextField;
if(myTextField == gender || myTextField == age || myTextField == ethnicity || myTextField == income || myTextField == cyclingFreq || myTextField == riderType || myTextField == riderHistory){
[myTextField resignFirstResponder];
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; //as we want to display a subview we won't be using the default buttons but rather we're need to create a toolbar to display the buttons on
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[actionSheet setActionSheetStyle:UIActionSheetStyleAutomatic];
// actionSheet.release;
// actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; //as we want to display a subview we won't be using the default buttons but rather we're need to create a toolbar to display the buttons on
//
// [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
// [actionSheet setActionSheetStyle:UIActionSheetStyleAutomatic];
// [actionSheet addSubview:pickerView];
// doneToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
// doneToolbar.barStyle = UIBarStyleBlackOpaque;
// [doneToolbar sizeToFit];
// NSMutableArray *barItems = [[[NSMutableArray alloc] init] autorelease];
//
// UIBarButtonItem *flexSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease];
// [barItems addObject:flexSpace];
//
// UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
// [barItems addObject:cancelBtn];
//
// UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
// [barItems addObject:doneBtn];
//TODO add a next and previous button to left side to take us to the next/previous thing. and switch to the right kind of input mode.
// [doneToolbar setItems:barItems animated:YES];
//
// [actionSheet addSubview:doneToolbar];
selectedItem = 0;
// Iterate over fields and populate uiactionsheet
if(myTextField == gender){
for(NSString *title in genderArray){
[actionSheet addButtonWithTitle:title];
}
}else if (myTextField == age){
for(NSString *title in ageArray){
[actionSheet addButtonWithTitle:title];
}
selectedItem = [user.age integerValue];
}else if (myTextField == ethnicity){
for(NSString *title in ethnicityArray){
[actionSheet addButtonWithTitle:title];
}
}else if (myTextField == income){
for(NSString *title in incomeArray){
[actionSheet addButtonWithTitle:title];
}
}else if (myTextField == cyclingFreq){
for(NSString *title in cyclingFreqArray){
[actionSheet addButtonWithTitle:title];
}
}else if (myTextField == riderType){
for(NSString *title in riderTypeArray){
[actionSheet addButtonWithTitle:title];
}
}else if (myTextField == riderHistory){
for(NSString *title in riderHistoryArray){
[actionSheet addButtonWithTitle:title];
}
}
// [actionSheet release];
// [pickerView selectRow:selectedItem inComponent:0 animated:NO];
// [pickerView reloadAllComponents];
//
// [actionSheet addSubview:pickerView];
//
[actionSheet showInView:self.view];
[actionSheet release];
//
// [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
}
// the user pressed the "Done" button, so dismiss the keyboard
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
NSLog(@"textFieldShouldReturn");
[textField resignFirstResponder];
return YES;
}
// save the new value for this textField
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSLog(@"textFieldDidEndEditing");
// save value
if ( user != nil )
{
if ( textField == email )
{
//enable save button if value has been changed.
if (email.text != user.email){
self.navigationItem.rightBarButtonItem.enabled = YES;
}
NSLog(@"saving email: %@", email.text);
[user setEmail:email.text];
}
if ( textField == homeZIP )
{
if (homeZIP.text != user.homeZIP){
self.navigationItem.rightBarButtonItem.enabled = YES;
}
NSLog(@"saving homeZIP: %@", homeZIP.text);
[user setHomeZIP:homeZIP.text];
}
if ( textField == schoolZIP )
{
if (schoolZIP.text != user.schoolZIP){
self.navigationItem.rightBarButtonItem.enabled = YES;
}
NSLog(@"saving schoolZIP: %@", schoolZIP.text);
[user setSchoolZIP:schoolZIP.text];
}
if ( textField == workZIP )
{
if (workZIP.text != user.workZIP){
self.navigationItem.rightBarButtonItem.enabled = YES;
}
NSLog(@"saving workZIP: %@", workZIP.text);
[user setWorkZIP:workZIP.text];
}
NSError *error;
if (![managedObjectContext save:&error]) {
// Handle the error.
NSLog(@"PersonalInfo save textField error %@, %@", error, [error localizedDescription]);
}
}
}
- (void)done
{
[email resignFirstResponder];
[homeZIP resignFirstResponder];
[workZIP resignFirstResponder];
[schoolZIP resignFirstResponder];
NSLog(@"Saving User Data");
if ( user != nil )
{
[user setAge:[NSNumber numberWithLong:ageSelectedRow]];
NSLog(@"saved age index: %@ and text: %@", user.age, age.text);
[user setEmail:email.text];
NSLog(@"saved email: %@", user.email);
[user setGender:[NSNumber numberWithLong:genderSelectedRow]];
NSLog(@"saved gender index: %@ and text: %@", user.gender, gender.text);
[user setEthnicity:[NSNumber numberWithLong:ethnicitySelectedRow]];
NSLog(@"saved ethnicity index: %@ and text: %@", user.ethnicity, ethnicity.text);
[user setIncome:[NSNumber numberWithLong:incomeSelectedRow]];
NSLog(@"saved income index: %@ and text: %@", user.income, income.text);
[user setHomeZIP:homeZIP.text];
NSLog(@"saved homeZIP: %@", homeZIP.text);
[user setSchoolZIP:schoolZIP.text];
NSLog(@"saved schoolZIP: %@", schoolZIP.text);
[user setWorkZIP:workZIP.text];
NSLog(@"saved workZIP: %@", workZIP.text);
[user setCyclingFreq:[NSNumber numberWithLong:cyclingFreqSelectedRow]];
NSLog(@"saved cycle freq index: %@ and text: %@", user.cyclingFreq, cyclingFreq.text);
[user setRider_type:[NSNumber numberWithLong:riderTypeSelectedRow]];
NSLog(@"saved rider type index: %@ and text: %@", user.rider_type, riderType.text);
[user setRider_history:[NSNumber numberWithLong:riderHistorySelectedRow]];
NSLog(@"saved rider history index: %@ and text: %@", user.rider_history, riderHistory.text);
//NSLog(@"saving cycling freq: %d", [cyclingFreq intValue]);
//[user setCyclingFreq:cyclingFreq];
NSError *error;
if (![managedObjectContext save:&error]) {
// Handle the error.
NSLog(@"PersonalInfo save cycling freq error %@, %@", error, [error localizedDescription]);
}
}
else
NSLog(@"ERROR can't save personal info for nil user");
// update UI
[delegate setSaved:YES];
//disable the save button after saving
self.navigationItem.rightBarButtonItem.enabled = NO;
[self.navigationController popViewControllerAnimated:YES];
}
/*
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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 Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 6;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case 0:
return nil;
break;
case 1:
return @"Tell us about yourself";
break;
case 2:
return @"Your typical commute";
break;
case 3:
return @"How often do you cycle?";
break;
case 4:
return @"What kind of rider are you?";
break;
case 5:
return @"How long have you been a cyclist?";
break;
}
return nil;
}
//- (UIView *)tableView:(UITableView *)tbl viewForHeaderInSection:(NSInteger)section
//{
// UIView* sectionHead = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tbl.bounds.size.width, 18)];
// sectionHead.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
// sectionHead.userInteractionEnabled = YES;
// sectionHead.tag = section;
//
// UILabel *sectionText = [[UILabel alloc] initWithFrame:CGRectMake(18, 8, tbl.bounds.size.width - 10, 18)];
//
// switch (section) {
// case 0:
// sectionText.text = @"Tell us about yourself";
// break;
// case 1:
// sectionText.text = @"Your typical commute";
// break;
// case 2:
// sectionText.text = @"How often do you cycle?";
// break;
// case 3:
// sectionText.text = @"What kind of rider are you?";
// break;
// case 4:
// sectionText.text = @"How long have you been a cyclist?";
// break;
// }
// sectionText.backgroundColor = [UIColor clearColor];
// sectionText.textColor = [UIColor colorWithHue:0.6 saturation:0.33 brightness: 0.49 alpha:1];
// //sectionText.shadowColor = [UIColor grayColor];
// //sectionText.shadowOffset = CGSizeMake(0,0.001);
// sectionText.font = [UIFont boldSystemFontOfSize:16];
//
// [sectionHead addSubview:sectionText];
// [sectionText release];
//
// return [sectionHead autorelease];
//}
//
//-(float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
// return UITableViewAutomaticDimension;
//}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch ( section )
{
case 0:
return 1;
break;
case 1:
return 5;
break;
case 2:
return 3;
break;
case 3:
return 1;
break;
case 4:
return 1;
break;
case 5:
return 1;
break;
default:
return 0;
}
return 0;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Set up the cell...
UITableViewCell *cell = nil;
// outer switch statement identifies section
switch ([indexPath indexAtPosition:0])
{
case 0:
{
static NSString *CellIdentifier = @"CellInstruction";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// inner switch statement identifies row
switch ([indexPath indexAtPosition:1])
{
case 0:
cell.textLabel.text = @"Questions? Contact Us";
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
break;
case 1:
{
static NSString *CellIdentifier = @"CellPersonalInfo";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// inner switch statement identifies row
switch ([indexPath indexAtPosition:1])
{
case 0:
cell.textLabel.text = @"Age Range";
[cell.contentView addSubview:age];
break;
case 1:
cell.textLabel.text = @"Email";
[cell.contentView addSubview:email];
break;
case 2:
cell.textLabel.text = @"Gender";
[cell.contentView addSubview:gender];
break;
case 3:
cell.textLabel.text = @"Ethnicity";
[cell.contentView addSubview:ethnicity];
break;
case 4:
cell.textLabel.text = @"Home Income";
[cell.contentView addSubview:income];
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
break;
case 2:
{
static NSString *CellIdentifier = @"CellZip";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
switch ([indexPath indexAtPosition:1])
{
case 0:
cell.textLabel.text = @"Home ZIP";
[cell.contentView addSubview:homeZIP];
break;
case 1:
cell.textLabel.text = @"Work ZIP";
[cell.contentView addSubview:workZIP];
break;
case 2:
cell.textLabel.text = @"School ZIP";
[cell.contentView addSubview:schoolZIP];
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
break;
case 3:
{
static NSString *CellIdentifier = @"CellFrequecy";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// inner switch statement identifies row
switch ([indexPath indexAtPosition:1])
{
case 0:
cell.textLabel.text = @"Cycle Frequency";
[cell.contentView addSubview:cyclingFreq];
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
break;
case 4:
{
static NSString *CellIdentifier = @"CellType";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// inner switch statement identifies row
switch ([indexPath indexAtPosition:1])
{
case 0:
cell.textLabel.text = @"Rider Type";
[cell.contentView addSubview:riderType];
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
break;
case 5:
{
static NSString *CellIdentifier = @"CellHistory";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// inner switch statement identifies row
switch ([indexPath indexAtPosition:1])
{
case 0:
cell.textLabel.text = @"Rider History";
[cell.contentView addSubview:riderHistory];
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
break;
// case 5:
// {
// static NSString *CellIdentifier = @"CellTextField";
// cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// if (cell == nil) {
// cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
// }
//
// // inner switch statement identifies row
// switch ([indexPath indexAtPosition:1])
// {
// case 0:
// cell.textLabel.text = @"Getting started with Cycle Philly";
// break;
// }
//
// cell.selectionStyle = UITableViewCellSelectionStyleNone;
// }
// case 2:
// {
// static NSString *CellIdentifier = @"CellCheckmark";
// cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// if (cell == nil) {
// cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
// }
//
// switch ([indexPath indexAtPosition:1])
// {
// case 0:
// cell.textLabel.text = @"Less than once a month";
// break;
// case 1:
// cell.textLabel.text = @"Several times per month";
// break;
// case 2:
// cell.textLabel.text = @"Several times per week";
// break;
// case 3:
// cell.textLabel.text = @"Daily";
// break;
// }
// /*
// if ( user != nil )
// if ( [user.cyclingFreq intValue] == [indexPath indexAtPosition:1] )
// cell.accessoryType = UITableViewCellAccessoryCheckmark;
// */
// if ( [cyclingFreq intValue] == [indexPath indexAtPosition:1] )
// cell.accessoryType = UITableViewCellAccessoryCheckmark;
// else
// cell.accessoryType = UITableViewCellAccessoryNone;
// }
}
// debug
//NSLog(@"%@", [cell subviews]);
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [anotherViewController release];
// outer switch statement identifies section
NSURL *url = [NSURL URLWithString:kInstructionsURL];
NSURLRequest *request = [NSMutableURLRequest requestWithURL:url];
switch ([indexPath indexAtPosition:0])
{
case 0:
{
// inner switch statement identifies row
switch ([indexPath indexAtPosition:1])
{
case 0:
[[UIApplication sharedApplication] openURL:[request URL]];
break;
case 1:
break;
}
break;
}
case 1:
{
switch ([indexPath indexAtPosition:1])
{
case 0:
break;
case 1:
break;
}
break;
}
case 2:
{
switch ([indexPath indexAtPosition:1])
{
case 0:
break;
case 1:
break;
}
break;
}
case 3:
{
switch ([indexPath indexAtPosition:1])
{
case 0:
break;
case 1:
break;
}
break;
}
case 4:
{
switch ([indexPath indexAtPosition:1])
{
case 0:
break;
case 1:
break;
}
break;
}
case 5:
{
switch ([indexPath indexAtPosition:1])
{
case 0:
break;
case 1:
break;
}
break;
}
// case 2:
// {
// // cycling frequency
// // remove all checkmarks
// UITableViewCell *cell;
// cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]];
// cell.accessoryType = UITableViewCellAccessoryNone;
// cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:2]];
// cell.accessoryType = UITableViewCellAccessoryNone;
// cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:2]];
// cell.accessoryType = UITableViewCellAccessoryNone;
// cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:2]];
// cell.accessoryType = UITableViewCellAccessoryNone;
//
// // apply checkmark to selected cell
// cell = [tableView cellForRowAtIndexPath:indexPath];
// cell.accessoryType = UITableViewCellAccessoryCheckmark;
//
// // store cycling freq
// cyclingFreq = [NSNumber numberWithInt:[indexPath indexAtPosition:1]];
// NSLog(@"setting instance variable cycling freq: %d", [cyclingFreq intValue]);
// }
}
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];