0

I'm bringing up a popover that has a field in it. I'm using "textFieldShouldEndEditing" to do some validation of the text. If the entered text is invalid, I return "NO".

The problem when I dismiss my popover. If the text is invalid, textFieldShouldEndEditing returns "NO". After I dismiss my popover, and click in any other text field, the field doesn't not get selected. I can't type in any other field, the keyboard doesn't show up.

What's the best way to avoid this behavior?

4

1 回答 1

0

我不完全确定您要达到的目标,但我认为您可以在关闭弹出窗口时进行一些检查。

-(void)dimissView
{
    //We already know we are going to dismiss the view right away, so we can set
    //[textField resignFirstResponder];, no matter if the text is valid or not

    if(textView.text is valid)//Create some condition
    {
        //tell the parentView that textField.text was valid
    }
    else
    {
        //Tell the parentView that textField.text was invalid   
    }

    [view dismissViewControllerAnimated:YES completion:nil];
}

当您找到一种方法来告诉弹出框的父级 textField 无效时,IE 设置 a bool textFieldTextWasValid = NO;,然后您可以轻松检查,并在您尝试在父级中选择另一个 textView 时做出适当的行为,或者不管你的情况是什么。

请注意,这不是工作代码,这只是一个想法,您需要理解它才能使其工作。

于 2013-08-22T14:30:29.110 回答