Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift:UITableViewCell中UITextField的委托不起作用_Swift_Uitableview_Delegates_Uitextfielddelegate - Fatal编程技术网

Swift:UITableViewCell中UITextField的委托不起作用

Swift:UITableViewCell中UITextField的委托不起作用,swift,uitableview,delegates,uitextfielddelegate,Swift,Uitableview,Delegates,Uitextfielddelegate,我正在尝试将我的标题f的委托设置为我的UITableViewCell或我的UITableView。这就是我在UITableViewCell类中设置文本字段的方法 class AddAppointmentTableViewCell: UITableViewCell, UITextFieldDelegate, UITextViewDelegate { var view = UIView() var titleTF = UITextField() func addTitle() -> UIVi

我正在尝试将我的
标题f
的委托设置为我的
UITableViewCell
或我的
UITableView
。这就是我在
UITableViewCell
类中设置文本字段的方法

class AddAppointmentTableViewCell: UITableViewCell, UITextFieldDelegate, UITextViewDelegate {
var view = UIView()
var titleTF = UITextField()

func addTitle() -> UIView {
    view = UIView(frame: CGRect(x: 0, y: 0, width: frame.width, height:
        NSAttributedString(string: "Enter Title", attributes: [.font: UIFont.boldSystemFont(ofSize: 24),
                                                               .foregroundColor: UIColor.lightGray]).size().height+30))

    titleTF.translatesAutoresizingMaskIntoConstraints = false
    titleTF.textAlignment = .left
    titleTF.delegate = self
    titleTF.attributedText = NSAttributedString(string: "Enter Title", attributes: [.font: UIFont.boldSystemFont(ofSize: 24),
                                                                                    .foregroundColor: UIColor.lightGray])
    titleTF.inputAccessoryView = toolBar
    view.addSubview(titleTF)
    titleTF.topAnchor.constraint(equalTo: view.topAnchor, constant: 15).isActive = true
    titleTF.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -15).isActive = true
    titleTF.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 15).isActive = true
    titleTF.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -15)
    return view
}

func textFieldDidEndEditing(_ textField: UITextField) {
    print("textFieldDidEndEditing")
}

override func draw(_ rect: CGRect) {
    addSubview(view)
}
}
这在我的
UITableView
类中:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return rows.count
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return rows[indexPath.row].frame.height
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! AddAppointmentTableViewCell
    cell.view = rows[indexPath.row]
    return cell
}
等于
[cell.addTitle(),cell.addNote()]


我不明白为什么我的
UITableViewCell
中的
textfieldDiBeginediting
方法没有被调用。

您需要添加这一行

{

textField.delegate=self


}您需要添加这一行

{

textField.delegate=self


}

您必须调用awakeFromNib中的代理(有相同的问题):


您必须调用awakeFromNib中的代理(有相同的问题):


显示您的
AddAppointmentTableViewCell
您希望看到什么?您的tableview单元格和
textfieldDiBeginediting
方法这就是您需要的所有内容吗?“titleTF.delegate=self”甚至没有人知道titleTF的定义位置和方式。显示您的
AddAppointmentTableViewCell
您希望看到什么?您的tableview单元格和
textfieldDiBeginediting
方法这就是您需要的一切吗?“titleTF.delegate=self”甚至没有人知道titleTF的定义位置和方式。
override func awakeFromNib() {
    super.awakeFromNib()
    textField.delegate = self
}