首页 > 解决方案 > 敲击时键盘打不开

问题描述

我在表格视图中有文本字段。每当点击文本字段时,就会出现另一行带有文本字段的行。但是点击文本字段时键盘没有打开。它正在创建一个文本字段,但键盘没有打开。这是我的代码:

@IBOutlet weak var contactPersonsTableView: UITableView!
var contactPersons = [String]()
var index = 0
override func viewDidLoad() {
    super.viewDidLoad()
    self.hideKeyboardWhenTappedAround()
    // Do any additional setup after loading the view.
}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return contactPersons.count + 1

}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "contactPersonCell", for: indexPath) as! ContactPersonTableViewCell
    cell.contactPerson.delegate = self
    cell.contactPerson.tag = indexPath.row
    return cell
}

func textFieldDidBeginEditing(_ textField: UITextField) {
index = textField.tag
textField.becomeFirstResponder()
    if(textField.text!.isEmpty)
    {
        contactPersons.insert("", at: index)
        contactPersonsTableView.reloadData()

    }

}

标签: iosswift

解决方案


推荐阅读