Я думаю, что у меня возникло недоразумение с делегатами по-быстрому. Я пытаюсь программно добавить textField в мой контроллер. Поэтому я отредактировал свой класс, как показано ниже:
class HomeController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UITextFieldDelegate {
}
В моем понимании, теперь я могу добавить UITextFieldDelegate в свое текстовое поле, и он будет вызывать расширение.
Но как-то каждый раз, когда я устанавливаю его делегат говорит мне, что:
Невозможно присвоить значение типа '(HomeController) -> () -> HomeController' для типа 'UITextFieldDelegate?'
Поэтому я хотел знаете, как я могу установить делегат моего TextField для UITextFieldDelegate?
Мой класс выглядит следующим образом:
class HomeController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UITextFieldDelegate {
let sampleTextField: UITextField = {
let textField = UITextField(frame: CGRect(x: 20, y: 100, width: 300, height: 40))
textField.placeholder = "Enter text here"
textField.font = UIFont.systemFont(ofSize: 15)
textField.borderStyle = UITextField.BorderStyle.roundedRect
textField.autocorrectionType = UITextAutocorrectionType.no
textField.keyboardType = UIKeyboardType.default
textField.returnKeyType = UIReturnKeyType.done
textField.clearButtonMode = UITextField.ViewMode.whileEditing
textField.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
textField.delegate = self
return textField
}()
}