我正在尝试对 UItextField 中的正确时间进行错误检查。我不想在用户输入时弹出错误(让他们有机会先修复它),所以我想我会在 EditingDidEnd 操作期间进行检查。我设置了小时、分钟和秒。这是我为 inHours 尝试的代码:
- (IBAction)inHourEditEnd:(id)sender
{
   // Check to make sure value is between 0 & 23 Hours
   if ([[[self inHour] text] intValue] >= 0 && [[[self inHour] text] intValue] < 24) {
      [self updateDuration];
   } else {
      NSString *errorDescription = [NSString stringWithFormat:@"%@ hours is not a valid start time. Please enter an hour between 0 and 23", [[self inHour] text]];
      UIAlertView *errorMessage = [[UIAlertView alloc] initWithTitle:@"Ivalid Hour for Start Time"
                                                                   message:errorDescription
                                                                  delegate:self
                                                         cancelButtonTitle:@"OK"
                                                         otherButtonTitles:nil];
            [errorMessage show];
            [_inHour becomeFirstResponder];
        }
    }
警报工作正常,但在显示警报后不会返回到文本字段(inHour)。它只是停留在我点击以导致 EditingDidEnd 的任何文本字段上。在此处搜索,我找到了一种使用以下代码使 alertView 将用户发送回正确文本框的方法:
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
   //Checks For Approval
   if (buttonIndex == 0) {
      [_inHour becomeFirstResponder];
   }
}
但这仅适用于第一个框,我需要使其与 inHour、inMinute 和 inSeconds 一起使用。
有什么建议可以让我完成这项工作吗?这些路径中的任何一条方向是否正确?
感谢您的任何帮助。