未调用 UITextFieldDelegate 方法 [英] UITextFieldDelegate method not called
本文介绍了未调用 UITextFieldDelegate 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在关注 Big Nerd Ranch iOS 编程书籍(Swift 版)并且我有这个文件.
I'm following the Big Nerd Ranch iOS Programming book (Swift version) and I have this file.
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 委托方法.我在控制台中看不到此处"日志.我已经多次检查命名和语法.有什么想法吗?
For some reason, the textField delegate method is not called. I can't see the "here" log in my console. I have double checked the naming and syntax a lot of times. Any ideas?
推荐答案
您需要将文本字段的委托设置为 self.
You need set delegate of your text field to self.
override func viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
}
这篇关于未调用 UITextFieldDelegate 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文