如何从UITableViewCell获取文本字段的值? [英] How To get values of textfields from a UITableViewCell?

查看:113
本文介绍了如何从UITableViewCell获取文本字段的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个具有4个UITextFieldUITableView单元格,我想在单击按钮时获取它们的值.

So I have thisUITableView cell that has 4 UITextField, and I want to get their values on button click.

此代码不会检索任何值.

This code does not retrieve any values.

@IBAction func printBtnAction(_ sender: Any) {

    let cell = self.myTableView.dequeueReusableCell(withIdentifier: "manualAddC1") as! AddFriendC1Cell

    let alias = cell.aliasTextField.text!
    let primaryPhone = cell.primaryPhoneTextField.text!
    let secondaryPhone = cell.seondaryPhoneTextField.text!
    let email = cell.emailAddressTextField.text!

    print("Alias: \(alias), Phone: \(primaryPhone), Phone2: \(secondaryPhone), Email: \(email)")
}

这是TableView的屏幕截图

This is the screenshot of the TableView

推荐答案

我终于通过这个简单的解决方案弄清楚了.

I finally figured it out with this simple solution.

@IBAction func saveBtnAction(_ sender: Any) {

    let index = IndexPath(row: 0, section: 0)
    let cell: AddFriendC1Cell = self.myTableView.cellForRow(at: index) as! AddFriendC1Cell
    self.alias = cell.aliasTextField.text!
    self.primaryPhone = cell.primaryPhoneTextField.text!
    self.secondaryPhone = cell.seondaryPhoneTextField.text!
    self.email = cell.emailAddressTextField.text!

    print("Alias: \(self.alias), Phone: \(self.primaryPhone), Phone2: \(self.secondaryPhone), Email: \(self.email)")
}

这篇关于如何从UITableViewCell获取文本字段的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆