Reputation: 16730
I have already looked at this solution. I have created a sample project showing the bug.
The view has only one UITextField on it.
and here is my code:
class ViewController: UIViewController {
@IBOutlet weak var mm: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
let x = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 40))
x.backgroundColor = .red
mm.inputAccessoryView = x
}
}
When I tap on the textfield, here is what happens: --> The red view appears at the bottom and is just stuck there no matter if the keyboard is dismissed or not. Any help please?
Upvotes: 0
Views: 265
Reputation: 494
You are just toggling the keyboard you are not actually dismissing the keyboard try to dismiss the keyboard.
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
let view = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 40))
view.backgroundColor = .red
textField.inputAccessoryView = view
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}
Upvotes: 2