在 UITableView 中编辑 UITextField(启用/禁用输入)?

发布于 2024-10-10 06:32:33 字数 339 浏览 2 评论 0原文

我正在尝试实现类似于苹果 Contact.app 的功能。

当用户在详细视图中按“编辑”时,文本字段应启用,而当用户按“完成/保存”时,应禁用输入 UITextFields。

所以我添加了:

-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField {
    return [(UITableView*)self.view isEditing];
}

并将控制器设置为每个文本字段的委托,但是如果用户在编辑时按“完成/保存”,键盘将保持打开状态,用户可以编辑字符串。我怎样才能确保这种情况不会发生?

Im trying to achieve something similar to Apples Contact.app.

When the user press Edit in the detail view the textfields should become enabled, and when the user presses Done/Save then the input UITextFields should be disabled.

So I added:

-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField {
    return [(UITableView*)self.view isEditing];
}

And set the controller to be the delegate for every textfield, but if the users presses Done/Save while editing is taking place the keyboard stays open and the user can edit the string. How can i make sure that this not happens?

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

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

发布评论

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

评论(2

鯉魚旗 2024-10-17 06:32:33

通过将文本字段的委托设置为单元格并实现这些方法来解决。

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    if (!editing)
        [textField resignFirstResponder];
}

- (BOOL) textFieldShouldBeginEditing:(UITextField *)textField {
    return [self isEditing];
}

Solved by setting the delegate of the textfield to the cell, and implementing these methods.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    if (!editing)
        [textField resignFirstResponder];
}

- (BOOL) textFieldShouldBeginEditing:(UITextField *)textField {
    return [self isEditing];
}
日暮斜阳 2024-10-17 06:32:33

您只处理了编辑的开始...您应该记录哪个 uitextbox 是第一响应者,然后如果您点击保存按钮,您应该在 texbox 上调用 resignFirstResponder 。

希望这有帮助,
莫西

you handled only the beggining of the edit ... you should record which uitextbox is the first responder then if you tap the save button you should invoke a resignFirstResponder on the texbox.

Hope this helps,
Moszi

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