Mercurial > hg > soniczoomios
view UsernameAlertViewController.mm @ 42:3d627dce8bf0
Tidied up startup logic.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Wed, 17 Apr 2013 13:44:05 +0100 |
parents | a42903c61558 |
children | 0d3a993405e4 |
line wrap: on
line source
// // iViewController.m // oscSenderExample // // Created by Robert Tubb on 07/01/2013. // // #include "eventLogger.h" #import "usernameAlertViewController.h" extern EventLogger eventLogger; @implementation UsernameAlertViewController -(void)showUserNamePrompt{ self.alert = [[UIAlertView alloc] initWithTitle:@"Hello!" message:@"Please enter your name:" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil]; self.alert.alertViewStyle = UIAlertViewStylePlainTextInput; UITextField * alertTextField = [self.alert textFieldAtIndex:0]; [alertTextField setDelegate:self]; alertTextField.keyboardType = UIKeyboardTypeDefault; alertTextField.placeholder = @"Username"; [self.alert show]; //[self.alert release]; } -(void)setAppRef:(id)theAppRef{ self.theOFAppRef = theAppRef; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"Entered: %@",[[alertView textFieldAtIndex:0] text]); NSString *userName = [[alertView textFieldAtIndex:0] text]; if ([userName isEqualToString:@""]){ [self showUserNamePrompt]; return; } eventLogger.setUsername([userName cStringUsingEncoding:NSASCIIStringEncoding]); ((testApp *)self.theOFAppRef)->startTimedSession(); } -(BOOL)textFieldShouldReturn:(UITextField *)textField{ NSLog(@"Entered: %@",[[self.alert textFieldAtIndex:0] text]); NSString *userName = [[self.alert textFieldAtIndex:0] text]; if ([userName isEqualToString:@""]){ [self showUserNamePrompt]; }else{ eventLogger.setUsername([userName cStringUsingEncoding:NSASCIIStringEncoding]); } [self.alert dismissWithClickedButtonIndex:self.alert.firstOtherButtonIndex animated:YES]; return YES; } - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView { UITextField *textField = [alertView textFieldAtIndex:0]; if ([textField.text length] == 0) { return NO; } return YES; } @end // global. again.