comparison UsernameAlertViewController.mm @ 0:a223551fdc1f

First commit - copy from tweakathlon.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 10 Oct 2014 11:46:42 +0100
parents
children 851833072cf1
comparison
equal deleted inserted replaced
-1:000000000000 0:a223551fdc1f
1 //
2 // iViewController.m
3 // oscSenderExample
4 //
5 // Created by Robert Tubb on 07/01/2013.
6 //
7 //
8 #include "testApp.h"
9 #include "eventLogger.h"
10
11 #import "usernameAlertViewController.h"
12
13
14 extern EventLogger eventLogger;
15
16 @implementation UsernameAlertViewController
17
18 -(void)showUserNamePrompt{
19
20
21 self.alert = [[UIAlertView alloc] initWithTitle:@"Hello!"
22 message:@"Please enter your name:"
23 delegate:self
24 cancelButtonTitle:@"Continue"
25 otherButtonTitles:nil];
26 self.alert.alertViewStyle = UIAlertViewStylePlainTextInput;
27 UITextField * alertTextField = [self.alert textFieldAtIndex:0];
28 [alertTextField setDelegate:self];
29 alertTextField.keyboardType = UIKeyboardTypeDefault;
30 alertTextField.placeholder = @"Username";
31 [self.alert show];
32 //[self.alert release];
33
34
35 }
36 -(void)setAppRef:(id)theAppRef{
37 self.theOFAppRef = theAppRef;
38 }
39
40 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
41
42 NSLog(@"Entered: %@",[[alertView textFieldAtIndex:0] text]);
43 NSString *userName = [[alertView textFieldAtIndex:0] text];
44 if ([userName isEqualToString:@""]){
45 [self showUserNamePrompt];
46 return;
47 }
48 eventLogger.setUsername([userName cStringUsingEncoding:NSASCIIStringEncoding]);
49
50 // call some start func
51 ((testApp *)self.theOFAppRef)->startTheTests();
52 // rememebr to change return func too!
53
54 }
55
56 -(BOOL)textFieldShouldReturn:(UITextField *)textField{
57
58 NSLog(@"Entered: %@",[[self.alert textFieldAtIndex:0] text]);
59 NSString *userName = [[self.alert textFieldAtIndex:0] text];
60 if ([userName isEqualToString:@""]){
61 [self showUserNamePrompt];
62
63 }else{
64 eventLogger.setUsername([userName cStringUsingEncoding:NSASCIIStringEncoding]);
65 ((testApp *)self.theOFAppRef)->startTheTests();
66
67 }
68 [self.alert dismissWithClickedButtonIndex:self.alert.firstOtherButtonIndex animated:YES];
69 return YES;
70 }
71
72 - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
73 {
74 UITextField *textField = [alertView textFieldAtIndex:0];
75 if ([textField.text length] == 0)
76 {
77 return NO;
78 }
79 return YES;
80 }
81
82
83 @end
84
85
86 // global. again.
87