我正在设计一个iOS应用程序,当在我的iPhone上按下回车键时,我希望它将我指向下一个文本字段。
我找到了一些类似的问题,并且有很好的答案,但它们都是Objective-C代码,我正在寻找Swift代码,目前我有以下代码:
func textFieldShouldReturn(emaillabel: UITextField) -> Bool{
return true
}
它被放置在与包含文本字段的UIView相连接和控制的文件中,但我不确定那是否是正确的位置。
好的,所以我尝试了这个并得到了这个错误:
//could not find an overload for '!=' that accepts the supplied arguments
func textFieldShouldReturn(textField: UITextField) -> Bool {
let nextTag: NSInteger = textField.tag + 1
// Try to find next responder
let nextResponder: UIResponder = textField.superview!.viewWithTag(nextTag)!
if (nextResponder != nil) {
// could not find an overload for '!=' that accepts the supplied arguments
// Found next responder, so set it.
nextResponder.becomeFirstResponder()
} else {
// Not found, so remove keyboard.
textField.resignFirstResponder()
}
return false // We do not want UITextField to insert line-breaks.
}