如何处理名称为“done”的键盘按钮在 iOS 中

发布于 2024-11-01 10:41:04 字数 367 浏览 4 评论 0原文

现在我有一个文本字段。

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

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

但是接下来,

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

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

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

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

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

谢谢大家

now i have a textField.

and i enter some words,the keyboard will appear.

when i pressed the keyboard "done",the keyboard will disappear. (i have finished this function)

but next,

i want to insert data using core data framework when the user pressed the button "done"

so,how to solve this problem?

i know how to insert data using core data,so you do not need to tell me how to insert the data.

i am using this code to disappear keyboard.

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

thanks everybody

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

所谓喜欢 2024-11-08 10:41:04

在示例代码中,我有 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;
}

In the example code, I have 3 UITextField. You can process your update after we reach the last field

// 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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文