为iPhone SDK使用带文本验证问题的FirstResponder
我正在尝试验证我的文本字段,这样,如果出现问题,用户输入将捕获它并显示警报(已获取该部分),而不会转到下一个字段(无法获取该部分)。你有没有想过我在这件事上做错了什么为iPhone SDK使用带文本验证问题的FirstResponder,iphone,Iphone,我正在尝试验证我的文本字段,这样,如果出现问题,用户输入将捕获它并显示警报(已获取该部分),而不会转到下一个字段(无法获取该部分)。你有没有想过我在这件事上做错了什么 - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == txtUserName) { [txtUserName2 becomeFirstResponder]; } else if (textF
- (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];
}
}
-(BOOL)textField应返回:(UITextField*)textField
{
if(textField==txTextSerName)
{
[txtUserName2成为第一响应者];
}
else if(textField==txtUserName2)
{
[txtUserName3成为第一响应者];
}
else if(textField==txtUserName3)
{
[txtUserName4成为第一响应者];
}
else if(textField==txtUserName4)
{
[txtUserName5成为第一响应者];
}
返回否;
}
-(void)textfielddidediting:(UITextField*)textField
{
if(textField==txTextSerName)
{
NSString*userNameOne=txtUserName.text;
double numOne=[userNameOne intValue];
如果(纽蒙尼<40 | |纽蒙尼>100)
{
//播放声音和振动以提高警觉
NSString*bonkSoundFile=[[NSBundle mainBundle]pathForResource:@“alertSound”类型:@“mp3”];
NSURL*fileURL=[NSURL fileURLWithPath:bonkSoundFile];
SystemSoundID BonkSondId;
AudioServicesCreateSystemSoundID((CFURLRef)fileURL和bonkSoundID);
AudioServicesPlaySystemSound(bonkSoundID);
AudioServicesPlaySystemSound(kSystemSoundID_振动);//振动
//显示警惕
UIAlertView*警报=[[UIAlertView alloc]
initWithTitle:@“年龄错误”
信息:@“您的年龄必须至少为40岁且小于100岁”
代表:无
取消按钮:@“确定”
其他按钮:无];
[警报显示];
[警报发布];
//如果出现错误,则不要转到下一个字段,而是将当前文本字段设置为//第一响应者
[txtUserName成为第一响应者];
}
}
以此类推,总共有五个字段。我只是不确定我做错了什么…您是否尝试将验证代码放入
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
当您不想继续下一个字段时,让它返回否?您是否尝试将验证代码放入
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
当你不想继续下一个领域时,让它返回否