Mercurial > hg > soniczoomios
comparison UsernameAlertViewController.mm @ 31:23ef179c3748
Ben / Christian 0.2
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 01 Mar 2013 13:28:45 +0000 |
parents | f42a00e3f22d |
children | a42903c61558 |
comparison
equal
deleted
inserted
replaced
30:c0a6f7c66719 | 31:23ef179c3748 |
---|---|
15 @implementation UsernameAlertViewController | 15 @implementation UsernameAlertViewController |
16 | 16 |
17 -(void)showUserNamePrompt{ | 17 -(void)showUserNamePrompt{ |
18 | 18 |
19 | 19 |
20 UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!" | 20 self.alert = [[UIAlertView alloc] initWithTitle:@"Hello!" |
21 message:@"Please enter your name:" | 21 message:@"Please enter your name:" |
22 delegate:self | 22 delegate:self |
23 cancelButtonTitle:@"Continue" | 23 cancelButtonTitle:@"Continue" |
24 otherButtonTitles:nil]; | 24 otherButtonTitles:nil]; |
25 alert.alertViewStyle = UIAlertViewStylePlainTextInput; | 25 self.alert.alertViewStyle = UIAlertViewStylePlainTextInput; |
26 UITextField * alertTextField = [alert textFieldAtIndex:0]; | 26 UITextField * alertTextField = [self.alert textFieldAtIndex:0]; |
27 [alertTextField setDelegate:self]; | |
27 alertTextField.keyboardType = UIKeyboardTypeDefault; | 28 alertTextField.keyboardType = UIKeyboardTypeDefault; |
28 alertTextField.placeholder = @"Username"; | 29 alertTextField.placeholder = @"Username"; |
29 [alert show]; | 30 [self.alert show]; |
30 [alert release]; | 31 [self.alert release]; |
31 | 32 |
32 | 33 |
33 } | 34 } |
34 | 35 |
35 | 36 |
44 eventLogger.setUsername([userName cStringUsingEncoding:NSASCIIStringEncoding]); | 45 eventLogger.setUsername([userName cStringUsingEncoding:NSASCIIStringEncoding]); |
45 | 46 |
46 | 47 |
47 } | 48 } |
48 | 49 |
50 -(BOOL)textFieldShouldReturn:(UITextField *)textField{ | |
51 | |
52 NSLog(@"Entered: %@",[[self.alert textFieldAtIndex:0] text]); | |
53 NSString *userName = [[self.alert textFieldAtIndex:0] text]; | |
54 if ([userName isEqualToString:@""]){ | |
55 [self showUserNamePrompt]; | |
56 | |
57 }else{ | |
58 eventLogger.setUsername([userName cStringUsingEncoding:NSASCIIStringEncoding]); | |
59 | |
60 } | |
61 [self.alert dismissWithClickedButtonIndex:self.alert.firstOtherButtonIndex animated:YES]; | |
62 return YES; | |
63 } | |
49 | 64 |
50 - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView | 65 - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView |
51 { | 66 { |
52 UITextField *textField = [alertView textFieldAtIndex:0]; | 67 UITextField *textField = [alertView textFieldAtIndex:0]; |
53 if ([textField.text length] == 0) | 68 if ([textField.text length] == 0) |