【发布时间】:2018-04-14 06:49:00
【问题描述】:
我有一个注册表单,其中包含多个 UITextfields 和 UIButton。我已经设置了UITextfield 代表,以便当用户开始在UITextfield 上编辑并按下返回键时,它会转到下一个UITextfield。
DoB、ISD Code、Gender 和 Nationality 为UIButtons,其中有IBActions,其余为UITextfields
是否可以在按文本字段中的return 键时启动UIButton 的IBAction。这样用户就可以按顺序将必要的数据添加到注册表单中。
到目前为止我做了什么..
func textFieldShouldReturn(_ textField: UITextField) -> Bool{
if let nextField = textField.superview?.viewWithTag(textField.tag + 1) as? UITextField
{
nextField.becomeFirstResponder()
}
else {
// Not found, so remove keyboard.
signupScrollView .setContentOffset(CGPoint( x: 0, y: 0), animated: true)
textField.resignFirstResponder()
return true
}
// Do not add a line break
return false
}
func textFieldDidBeginEditing(_ textField: UITextField) {
signupScrollView .setContentOffset(CGPoint( x: 0, y: textField.center.y-200), animated: true)
}
【问题讨论】:
-
你不会像这样触发
@IBAction,你只需调用@IBaction调用的同一个函数。 -
您想以编程方式调用
@IBAction对吗?就像我在Email字段上一样,我从键盘上按下return键,而不是DoB动作应该触发。 -
@Kuldeep 是的...
-
如果我在 else 部分调用 IBAction 并在 IBAction 结束时调用启动文本字段委托怎么办?
-
@alpha47 你的
buttons 和textFields 有共同的顺序标签吗?
标签: ios swift uitextfield ibaction uitextfielddelegate