哪个 UITextField 委托方法将在不重新键盘的情况下被调用?
我遇到的情况是,用户在不退出键盘的情况下将数据输入到 UITextField 中,然后按“下一步”按钮转到下一页。
该文本字段位于 UITextView 的自定义单元格中
。现在我想捕获每个文本字段和文本字段中的所有内容。当用户进入该 UITableView 的 UITextView 时,因为在单击“下一步”按钮时我需要保存数据。
到目前为止,我已经实现了以下方法,但当用户在 TextField 中输入数据并直接按 Next 按钮而不返回键盘时,这些方法都不会被调用,
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSString *strTitle = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
textField.text = strTitle;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
在 Next 之前从该 TextFields 保存的最佳方式是什么?
I am in situation where user enters data into UITextField in without resign of keyboard he presses Next button go to next page.
That textfield is in custom cell with UITextView
. Now I want to capture everything in every textfield & UITextView of that UITableView when user enters into it because at time of Next button click I need to save the data.
Till Now I have implemented below methods but none of these getting called when user enters data into TextField and directly press Next button without returning keyboard
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSString *strTitle = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
textField.text = strTitle;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
What could be the best wat to save from that TextFields before Next?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您失去焦点时,textFieldDidEndEditing 并不总是被调用。请参阅帖子https://stackoverflow.com/a/1229914/641062。它解释了有关 endEditing 方法行为的更多信息。
所以必须用这个方法保存你的数据。这将调用您输入的每个字符。
textFieldDidEndEditing in not always called when you lose the focus. see the post https://stackoverflow.com/a/1229914/641062. It explains a bit about more about the endEditing method's behaviour.
So must save your data in this method. This will called for every character you type.
至少应该调用其中之一。
不过,可能是非常简单的事情:您是否仔细检查过实现这些方法的类实际上已被指定为相关 UITextField 的委托?
At least one of those definitely should be called.
Could be something really simple, though: have you double-checked that the class implementing those methods has actually been assigned as the delegate of the UITextField in question?
如果您只想知道用户点击下一个按钮时文本字段和文本视图的内容,那么您不需要知道将调用哪个委托方法,您可以简单地在下一个按钮的 IBAction 方法中获取这些值
希望这有帮助!
If you just want to know the content of your textfield and textview when user taps the next button then you don't need to know which delegate method will be called, you can simply get those values in the IBAction method for next button
Hope this helps!
如果您使用自定义单元格,请使用此
If you are using a custom cell then use this