0

I have a UITextField in the event calls a function EditingDidEnd A to validate the contents of the field, then I have a button that calls a function B by passing the contents of text field and then brings me to another view which shows the results . The issue is that if the text field is empty by giving the button brings me to the view of results and then shows me the error that the field is empty ... :) Typical rookie with the theme events ... What you suggest I use? Exit on I put a function that validates for not following that execution??!

Thanks in advance,

4

2 回答 2

0

只需检查您的委托方法中的空文本,如果它是空的,则什么也不做。

if (!textField.text || [textField.text isEqualToString:@""])
   return;
于 2012-06-23T11:51:42.527 回答
0

按下按钮时进行验证

-(void)buttonNextClicked:(id)sender
{
     if(!self.textField.text || [self.textField.text isEqualToString:@""])
     {
          // Show an alert with validation message
          return;
     }

     //Proceed with the new view
}

如果您想在编辑停止后立即进行验证,请创建一个验证方法并在两个地方调用它

-(BOOL)isInputTextValid:(NSString *)txt
{
    if(!txt)
       return NO;
    if([txt isEqualToString:@""])
       return NO;
    if(other_invalid_values)
       return NO;

    return YES;
}
于 2012-06-23T11:53:54.607 回答