How to dismiss keyboard when touching anywhere outside UITextField (in swift)?

Edited for Swift 4 Edit: Added @objc. While this isn’t the best option for performance, one instance of it here shouldn’t cause too many problems until there is a better solution. Edited to fix when needing to interact with items behind GestureRecognizer. Edit: Thanks @Rao for pointing this out. Added tap.cancelsTouchesInView = false. This should … Read more

dismiss keyboard with a uiTextView

This works for me: import UIKit class ViewController: UIViewController, UITextViewDelegate { @IBOutlet weak var textView: UITextView! override func viewDidLoad() { super.viewDidLoad() textView.delegate = self } /* Updated for Swift 4 */ func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { if(text == “\n”) { textView.resignFirstResponder() return false } return true } … Read more

HW kbd Failed to set (null) as keyboard focus ios

I’ve just encountered this exception running a Xamarin app on the simulator. It started occurring after I toggled the software keyboard off while debugging the app. Given the exception mentioning the keyboard I think that’s what caused it. Uninstalling the app from the emulator, cleaning and rebuilding fixed the issue for me. Unsure if this … Read more

Getting keyboard size from userInfo in Swift

There are some problems in your line: var keyboardSize = notification.userInfo(valueForKey(UIKeyboardFrameBeginUserInfoKey)) notification.userInfo returns an optional dictionary [NSObject : AnyObject]?, so it must be unwrapped before accessing its values. The Objective-C NSDictionary is mapped to a Swift native Dictionary, so you must use the dictionary subscript syntax (dict[key]) to access the values. The value must be … Read more

Dismiss keyboard by touching background of UITableView

This is easily done by creating a UITapGestureRecognizer object (by default this will detect a “gesture” on a single tap so no further customization is required), specifying a target/action for when the gesture is fired, and then attaching the gesture recognizer object to your table view. E.g. Perhaps in your viewDidLoad method: UITapGestureRecognizer *gestureRecognizer = … Read more

How to make return key on iPhone make keyboard disappear?

First you need to conform to the UITextFieldDelegate Protocol in your View/ViewController’s header file like this: @interface YourViewController : UIViewController <UITextFieldDelegate> Then in your .m file you need to implement the following UITextFieldDelegate protocol method: – (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } [textField resignFirstResponder]; makes sure the keyboard is dismissed. Make sure you’re … Read more

How to get height of Keyboard?

Swift You can get the keyboard height by subscribing to the UIKeyboardWillShowNotification notification. (Assuming you want to know what the height will be before it’s shown). Swift 4 NotificationCenter.default.addObserver( self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil ) @objc func keyboardWillShow(_ notification: Notification) { if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { let keyboardRectangle = … Read more

Programmatically change UITextField Keyboard type

There is a keyboardType property for a UITextField: typedef enum { UIKeyboardTypeDefault, // Default type for the current input method. UIKeyboardTypeASCIICapable, // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active UIKeyboardTypeNumbersAndPunctuation, // Numbers and assorted punctuation. UIKeyboardTypeURL, // A type optimized for URL entry (shows . / .com prominently). UIKeyboardTypeNumberPad, // … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)