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
I suppose your tableViewCells are not dynamic. Your cell method will looks like this.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "YourCellID") as! YourClass
cell.yourTextField.tag = indexPath.row
//
// Alias will be tag 0
// Primary Phone will be tag 1
// Secondary Phone will be tag 2
// Email Address will be tag 3, so on and so forth
// Then, attach to each delegate
//
cell.yourTextField.delegate = self
}
Inside your UITableView handling class (which conforms to UITextFieldDelegate protocol), write this.
func textField(_ textField: UITextField, shouldChangeCharactersIn range:NSRange, replacementString string: String) -> Bool {
let kActualText = (textField.text ?? "") + string
switch textField.tag
{
case 0:
aliasValueHolder = kActualText;
case 1:
primaryPhoneValueHolder = kActualText;
case 2:
secondaryPhoneValueHolder = kActualText;
case 3:
emailAddressValueHolder = kActualText;
default:
print("It is nothing");
}
return true;
}
Then you can submit it.