加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 如何从UITableViewCell获取文本字段的值?

发布时间:2020-12-14 17:17:31 所属栏目:百科 来源:网络整理
导读:所以我有这个具有4个UITextField的UITableView单元格,我想在按钮点击时获取它们的值. 此代码不检索任何值. @IBAction func printBtnAction(_ sender: Any) { let cell = self.myTableView.dequeueReusableCell(withIdentifier: "manualAddC1") as! AddFriend
所以我有这个具有4个UITextField的UITableView单元格,我想在按钮点击时获取它们的值.

此代码不检索任何值.

@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的屏幕截图

enter image description here

解决方法

我终于通过这个简单的解决方案找到了答案.

@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)")
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读