[英]iOS - Change a ViewController with the keyboard “next” button?
I've noticed it's possible to trigger actions and to move through text fields using the done/next/return key in the bottom right of the iOS keyboard. 我注意到可以使用iOS键盘右下角的done / next / return键触发操作并在文本字段中移动。 Would it be possible to maybe change a view or trigger a segue with that button?
是否可以使用该按钮更改视图或触发segue?
For example, it would be cool to be able to type something into a UITextField, and then just tap "Next" to move onto the next viewController instead of having to use a separate button, or navigation item. 例如,能够在UITextField中输入内容,然后点击“下一步”移动到下一个viewController而不必使用单独的按钮或导航项是很酷的。
May be a stupid question, but something that I've been wondering if it was possible for a while. 可能是一个愚蠢的问题,但我一直想知道它是否有可能存在一段时间。
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
//Next button was pressed
//Push some viewcontroller here
return YES;
}
make sure you set the delegate of the UITextField to self 确保将UITextField的委托设置为self
It is possible. 有可能的。 If it's a UITextField, you can implement textFieldShouldReturn:.
如果它是UITextField,则可以实现textFieldShouldReturn:。 If it's a UITextView, you implement textView:shouldChangeTextInRange:replacementText:, and look for \\n in the replacement text.
如果是UITextView,则实现textView:shouldChangeTextInRange:replacementText:,并在替换文本中查找\\ n。
In either case, you can then perform a segue, do a navigation or modal push, etc. 在任何一种情况下,您都可以执行segue,执行导航或模态推送等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.