Disabling keyboard while editing UItextfield in Swift
I want to make a calculator with two text boxes. there are buttons with numbers and buttons for math operations. but I couldn't get the keyboard out of the way when the textbox was clicked. I never want to show the keyboard, but I want to edit the textbox with the number buttons.
touchbegans or textFieldShoulBeginEditing method didn't work for me.
source to share
Edit
This workaround was specific to the above question, so please stop this poll. It's not just a keyboard shutdown. It is about the ability to edit a text field using a custom InputView and edit a text field in the absence of a visible keyboard.
This will cause the textbox keyboard to disappear and be editable.
Objective-C
yourTextField.inputView = [[UIView alloc] initWithFrame:CGRectZero];
Swift
yourTextField.inputView = UIView(frame: CGRectZero)
source to share
The answer to your question on how to remove keyboard in Xcode 6.1 with Swift is below:
import UIKit
class ItemViewController: UIViewController, UITextFieldDelegate {
@IBOutlet var textFieldItemName: UITextField!
@IBOutlet var textFieldQt: UITextField!
@IBOutlet var textFieldMoreInfo: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
textFieldItemName.delegate = self
textFieldQt.delegate = self
textFieldMoreInfo.delegate = self
}
...
/**
* Called when 'return' key pressed. return NO to ignore.
*/
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
/**
* Called when the user click on the view (outside the UITextField).
*/
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
self.view.endEditing(true)
}
}
source to share