UITableView 内的 UITextField
我在 UITableView 中有 UITextField 。我已经在 UITableView 的 cellForRowAtIndexPath 方法中设置了文本视图的委托,如下所示,
cell.textField.delegate = self;
但是当我完成编辑并按“完成”时,我在委托方法中没有得到任何内容,如下所示。可能是什么原因?
-(void) textFieldDidEndEditing: (UITextField * ) textField {
NSLog(@"here");
}
I have UITextField inside a UITableView. I've set the delegate of the text view in the cellForRowAtIndexPath method of my UITableView as follows
cell.textField.delegate = self;
but when I finished editing and press "done" I didn't get anything in my delegate method as shown below. What could be the reason?
-(void) textFieldDidEndEditing: (UITextField * ) textField {
NSLog(@"here");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
textFieldDidEndEditing:
方法在文本字段放弃第一响应者状态后调用。要让文本字段放弃第一响应者状态,请向其发送resignFirstResponder
消息。执行此操作的好地方是在文本字段委托的textFieldShouldReturn:
方法中。它看起来像这样:当用户点击“完成”键时,将调用
textFieldShouldReturn:
方法,导致文本字段放弃第一响应者状态和textFieldDidEndEditing:
被调用。The
textFieldDidEndEditing:
method is called after the text field resigns first responder status. To get the text field to resign first responder status, send it aresignFirstResponder
message. A good place to do that is in the text field delegate'stextFieldShouldReturn:
method. It would look something like this:When the user taps the "Done" key, the
textFieldShouldReturn:
method will get called, causing the text field to resign first responder status andtextFieldDidEndEditing:
to be called.