是否可以在按下键盘上的特定按钮时调用函数?
如:
if (textField.spaceIsClicked){
checkWords();
}
最佳答案
您可以这样使用 UITextFieldDelegate
的委托(delegate)函数 shouldChangeCharactersInRange
:
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textF: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
textF.delegate = self
}
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
if string == " " {
//Run your function here
println("SpaceBar is pressed")
}
return true
}
}
关于ios - 在 Swift 中按下特定的键盘按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31784288/