在 UITableView 中编辑 UITextField(启用/禁用输入)?
我正在尝试实现类似于苹果 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过将文本字段的委托设置为单元格并实现这些方法来解决。
Solved by setting the delegate of the textfield to the cell, and implementing these methods.
您只处理了编辑的开始...您应该记录哪个 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