私はテーブルビューを持っています。その中で私はUITextField
を動的に作成しています。 しかし、私はそれでイベントを発生させることはできません。テーブルビューにあるので、UITextFieldにデリゲートを割り当てることができません。
func tableView(_ tableView: UITableView, cellForRowAt indexPath:IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath) as! DynamicTableCell
var dynamicTxtField1: UITextField = UITextField()
dynamicTxtField1.backgroundColor = UIColor.white
dynamicTxtField1.rightViewMode = .always
dynamicTxtField1.layer.cornerRadius = 5;
dynamicTxtField1.clipsToBounds = true
dynamicTxtField1.borderStyle = .roundedRect
// Here i am not able to assign the
//Error in this line // dynamicTxtField1.delegate = self
// Here object "self" is referring to the view. Because of this i am not able to fire any events of the UITextField
cell.addSubview(dynamicTxtField1)
}
私はそれからいくつかの値を選択するビューを表示するためにイベントを発生できるように、このシナリオでのUITextFieldにデリゲートを割り当てる方法を提案してください。
エラーは次のとおりです。
ライン上
を "UITextFieldDelegateを入力しVIEWNAME(クラス名)の値を割り当てることができません":
dynamicTxtField1.delegate = self
のですか?あなたの 'self'は' UITextFieldDelegate'に従っていますか? – Grimxn
エラーに関する質問を投稿するときは、完全で正確なエラーメッセージを質問に含める必要があります。 – rmaddy
エラーは「ViewName(クラス名)の値をUITextFieldDelegateに割り当てることができません」です。 自己が問題となっているUITextFieldDelegateを参照していません。私は今どうすればいい? – Dev