How To get values of textfields from a UITableViewCell?

后端 未结 6 1671
天命终不由人
天命终不由人 2021-01-01 02:13

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 valu

6条回答
  •  臣服心动
    2021-01-01 02:21

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

提交回复
热议问题