我有一個表視圖。我正在動態創建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分配在這種情況下,這樣我可以觸發事件,以顯示視圖從中挑選一些價值。
的錯誤是:
「無法分配VIEWNAME(類名)的值鍵入UITextFieldDelegate」 就行了
:
dynamicTxtField1.delegate = self
什麼是錯誤您收到?你的'self'符合'UITextFieldDelegate'嗎? – Grimxn
發佈有關錯誤的問題時,需要在問題中包含完整的確切錯誤消息。 – rmaddy
錯誤是「無法將ViewName(classname)的值分配爲鍵入UITextFieldDelegate」。 自我並不是指UITextFieldDelegate就是問題所在。我現在應該怎麼做? – Dev