I'm trying to configure the cells of my table view to have different different keyboard configurations based upon what type of cell is being displayed.
In my func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell method, I have the following code to check for the value of the UILabel.text on the keyboard appropriately:
if cell.entityLabel.text == "Home" || cell.entityLabel.text == "Mobile" {
cell.entityTextField.keyboardType = UIKeyboardType.namePhonePad
}
However, these cells still display the same "default" keyboard.
Any idea what I may be missing?
EDIT: I had forgotten something important! These UITableView cells are actually being created in a separate class, EditTableViewCell.swift. So, I modified the awakeFromNib() method as shown below (but still getting the same results):
override func awakeFromNib() { super.awakeFromNib() // Initialization code
if entityLabel.text == "Home" || entityLabel.text == "Mobile" {
entityTextField.keyboardType = UIKeyboardType.namePhonePad
entityTextField.reloadInputViews()
}
else {
entityTextField.keyboardType = UIKeyboardType.default
entityTextField.reloadInputViews()
}
}
Add else statement to your expression for correct reuse logic, for example: