如何在文本字段中输入textFieldDidEndEditing之后的值

时间:2018-09-29 06:07:42

标签: ios

UITableViewCell中,我有UITextField。 我的代码在下面。

func textFieldShouldClear(_ textField: UITextField) -> Bool {
    return true
}

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
    return true;
}

func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
    return true;
}

func textFieldDidBeginEditing(_ textField: UITextField) {
    texttype.text = ""
    texttype.placeholder = ""
}

func textFieldDidEndEditing(_ textField: UITextField) {
    self.TextAction(texttype)
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    print(texttype.text)
    texttype.resignFirstResponder()
    return true
}

var textadd : ((NH_QuestionListCell) -> Void)?
@IBAction func TextAction(_ sender: UITextField) {

    print(texttype.text)
    //    self.question.text = texttype.text

    let index = texttype.tag
    self.textname = texttype.text

    print(self.textname)
    print(texttype.text)

    sender.resignFirstResponder()
    textadd?(self)
}

所以我的问题是:-在文本字段中输入文本后,按Enter键,输入的值就是Enter。但是如果我不输入Enter键,那么输入的值不输入怎么解决?

我在viewcontroller中的代码:-

cell.textadd = {[weak self] in

let model =    self?.questionViewModel.datafordisplay(atindex: indexPath)
print(model?.values)

let text1 = cell.texttype.text
print(text1)

self?.questionViewModel.setData(atIndex: indexPath, text: text1!, Option: model!)
cell.texttype.text = model?.values
//cell.texttype.isHidden = true
cell.textFieldShouldReturn(cell.texttype)

if let i = self?.tableview.indexPath(for: $0) {

    print("the selected text\(cell.textname ?? "")")

    print(i)

    print("the Selected button is \(cell.textname ?? "")")

    print(i)
    print(cell.textname)
    print(indexPath.row)
    print(indexPath.section)

    if model?.values == cell.texttype.text{
        cell.texttype.text = model?.values
        cell.texttype.placeholder = model?.values

    }else{
        cell.texttype.text = ""
    }

    let model = self?.questionViewModel.datafordisplay(atindex: indexPath)
    print(model?.values ?? "")

    print("Section \(indexPath.section), Row : \(indexPath.row)")

    let indexPath = IndexPath(row: indexPath.row, section:indexPath.section);
    self?.tableview.selectRow(at: indexPath, animated: false, scrollPosition: UITableViewScrollPosition.none)

    self?.tableView((self?.tableview)!, didSelectRowAt: indexPath)

}
print(cell.texttype.text ?? "")
self?.u = 1
}

如何解决此问题。

0 个答案:

没有答案