Hi all I got this to work but confused by other examples and if I am doing it correctly..
Like I said above works just wondering about the discrepancy between examples I found on web and what I need to do. Is it because the UIAlert is controller for the view and therefore I need to pass the textfield up through it, to self. Is there a better way to do this. will I run into any error later on doing it this way?
thanks
Ian
Code:
-(void)showWinAlert
{
NSLog(@"gameTime was:%@",userScore.gameTime);
NSMutableString *messageAlert = [[NSMutableString alloc]initWithFormat:
@"with Time: %@",userScore.gameTime];
// Testing alert //
winAlert = [[UIAlertView alloc] initWithTitle:@"New High Score!!!"
message:messageAlert
delegate:self
cancelButtonTitle:@"OK !"
otherButtonTitles:nil];
// if High Score then //
[winAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
[winAlert textFieldAtIndex:0].keyboardAppearance = UIKeyboardAppearanceAlert;
[winAlert becomeFirstResponder];
[[winAlert textFieldAtIndex:0] setTextAlignment:UITextAlignmentCenter];
[winAlert textFieldAtIndex:0].text=@"YourName";
// hilight all the text in the field //
// delegate the textfield in the Alert so we can limit size of input //
UITextField *theTitleTextField = [winAlert textFieldAtIndex:0];
// **this is the confusing line. makes sense to me but..
theTitleTextField.delegate = [winAlert delegate];
// ** most examples I found say this but this gives me an warning.
// warning: Semantic Issue: Assigning to 'id<UITextFieldDelegate>' from incompatible type 'HighScoreViewControl'
theTitleTextField.delegate = self;
[myTable reloadData];
[winAlert show];
}
// then I do this //
// Limit textfield to MAXTEXT //
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([textField.text length] >= MAXLENGTH) {
textField.text = [textField.text substringToIndex:MAXLENGTH-1];
NSLog(@"calling Limit input");
return NO;
}
return YES;
}
Like I said above works just wondering about the discrepancy between examples I found on web and what I need to do. Is it because the UIAlert is controller for the view and therefore I need to pass the textfield up through it, to self. Is there a better way to do this. will I run into any error later on doing it this way?
thanks
Ian