Hello,
New here and new to coding. I am trying to add a done button on a numeric keyboard. I saw a post here from 2019 that showed how but when I use the code I do not have the button on the keyboard and now my app is crashing. Any help would greatly be appreciated. Like I said, I am new to coding and I am way over my skill level here. Below is my code and a link to the thread from 2019.
override func viewDidLoad() {
super.viewDidLoad()
// Add Done Button
func addDoneButtonOnNumpad(textField: UITextField) {
let keypadToolbar: UIToolbar = UIToolbar()
// add a done button to the numberpad
keypadToolbar.items=[
UIBarButtonItem(title: "Done", style: UIBarButtonItem.Style.done, target: textField, action: #selector(UITextField.resignFirstResponder)),
UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: self, action: nil)]
keypadToolbar.sizeToFit()
// add a toolbar with a done button above the number pad
textField.inputAccessoryView = keypadToolbar
}
}
Thank you! I changed the code and I do have the “Done” button now. However, when I click done the app crashes. Would it be because I have not added that code for every UITextField?