【问题标题】:how to deal with the keyboard button which name is "done" in ios如何处理ios中名称为“done”的键盘按钮
【发布时间】:2011-04-17 00:38:19
【问题描述】:

现在我有一个文本字段。

我输入一些单词,键盘就会出现。

当我按下键盘“完成”时,键盘将消失。 (我已经完成了这个功能)

接下来,

当用户按下“完成”按钮时,我想使用核心数据框架插入数据

那么,如何解决这个问题?

我知道如何使用核心数据插入数据,所以你不需要告诉我如何插入数据。

我正在使用此代码来消失键盘。

-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  [txtName resignFirstResponder];
  return YES;
}

谢谢大家

【问题讨论】:

    标签: ios button keyboard


    【解决方案1】:

    在示例代码中,我有 3 个 UITextField。您可以在我们到达最后一个字段后处理您的更新

    // I the tag property to indicate which field I am on during runtime
    enum {
        Line1Tag = 50,
        Line2Tag,
        Line3Tag
    };
    
    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
        // The user has pressed the "Return Key"
        // Which I have set to "Next" for first two lines
        // and "Done" for the last line, so jump to the next text field
        NSLog(@"\"Return\" key pressed.");
    
        // based on which text field we are in jump to the next
        if (textField.tag == Line3Tag)
            // We have reach the last line so hide keyboard
            [textField resignFirstResponder];
    
            // this is where you can perform Core Data updates if you like
    
        else {
            int nextTag = textField.tag + 1;
            UIView *nextField = [self.view viewWithTag:nextTag];
            [nextField becomeFirstResponder];
    
            // Once the next text field is the first responder
            // I need to make sure the user can see it
            [self makeActiveTextFieldVisible];
        }
        return NO;
    }
    

    【讨论】:

    • 谢谢,它可以工作。但是 stackoverflow.com 不能让我提交新页面
    猜你喜欢
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 2015-03-14
    • 2013-11-25
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多