Я пытаюсь проверить свои текстовые поля, чтобы при возникновении проблемы пользовательский ввод перехватывал его и показывал предупреждение (получил эту часть), а не переходил к следующему полю (не может получить эту часть) , Есть мысли о том, что я делаю не так с этим?
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == txtUserName)
{
[txtUserName2 becomeFirstResponder];
}
else if (textField == txtUserName2)
{
[txtUserName3 becomeFirstResponder];
}
else if (textField == txtUserName3)
{
[txtUserName4 becomeFirstResponder];
}
else if (textField == txtUserName4)
{
[txtUserName5 becomeFirstResponder];
}
return NO;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if (textField == txtUserName)
{
NSString *userNameOne = txtUserName.text;
double numOne = [userNameOne intValue];
if(numOne < 40 || numOne > 100)
{
//play sound and vibrate for alert
NSString *bonkSoundFile = [[NSBundle mainBundle] pathForResource:@"alertSound" ofType:@"mp3"];
NSURL *fileURL = [NSURL fileURLWithPath:bonkSoundFile];
SystemSoundID bonkSoundID;
AudioServicesCreateSystemSoundID( (CFURLRef) fileURL, &bonkSoundID);
AudioServicesPlaySystemSound(bonkSoundID);
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate); //vibrate
//show alert
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Age Error"
message:@"Your age must be at least 40 years old and less than 100 years old"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
//if there is an error, then don't go to next field but make current textField the //FirstResponder
[txtUserName becomeFirstResponder];
}
}
и так далее, всего пять полей. Я просто не уверен, что я делаю не так ...