我正在关注 Big Nerd Ranch iOS 编程书籍(Swift 版)并且我有这个文件。
import UIKit
class ConversionViewController: UIViewController, UITextFieldDelegate {
@IBOutlet var celsiusLabel: UILabel!
@IBOutlet var textField: UITextField!
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
print("here")
return true
}
//rest of the code here
}
由于某种原因,没有调用 textField 委托(delegate)方法。我在控制台中看不到“此处”日志。我多次仔细检查了命名和语法。有什么想法吗?
最佳答案
您需要将文本字段的委托(delegate)设置为自己。
override func viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
}
关于ios - 未调用 UITextFieldDelegate 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34842153/