I know that when down arrow key is pressed on keyboard then we can get Keyboard Hide notification but the problem is, we get Keyboard Hide notification also when we rotate the device and keyboard hides, now how to differentiate that keyboard is hiding because of key pressed not because of rotation.
In your AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter]
addObserver:self selector:#selector(keyboardWillHide)
name:UIKeyboardWillHideNotification object:nil];
return YES;
}
-(void) keyboardWillHide {
NSLog(#"Bye");
}
Following Delegate method of textfield is called automatically when we clicked on the return or arrow button of keyboard.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
Related
I have HTML pages with textfields and after touch on any of this textfield in UIWebView, I need to show UIPopOver with the static information and hide a keyboard.
How I can do this?
set the textfield's inputview to nil.
textField.inputView = nil;
Put this code in you viewDidLoad method, it is notification that notify you when keyboard is display
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidShow) name:UIKeyboardDidShowNotification object:nil];
Add you popup view in UITextField in following method of notification
- (void)keyboardDidShow
{
if(self.myTextFieldName)
{
[myTextFieldName resignFirstResponder]; /// resignFirstResponder/hideKeyBoard when you click on UITextFiled
myTextFieldName.inputView = self.PopUpView. // and add your popup view as input view of yourTextFiled
}
}
I have a custom NSWindow class that has the following methods:
- (void)setupWindowForEvents{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(windowDidResignKey:) name:NSWindowDidResignMainNotification object:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:self];
}
-(void)windowDidResignKey:(NSNotification *)note {
NSLog(#"notification");
[self close];
}
I call [_window setupWindowForEvents]; but the windowDidResignKey never gets called.
This is how I call my NSWindow: when the status bar item is clicked I makeKeyAndOrderFront and the Window is displayed right beneath the status bar item, like this:
Any ideas why the I don't get any notification when the window loses focus? I've used both NSWindowDidResignMainNotification and NSWindowDidResignKeyNotification to see if any of these worked, but none is working.
You're probably not getting the notification because you actually are never key in the first place. Your window appears to be borderless, and borderless windows don't grab key window status by default.
In your window subclass, be sure to return YES on the following methods:
- (BOOL)canBecomeKeyWindow {
return YES;
}
- (BOOL)canBecomeMainWindow {
return YES;
}
I am noticing that after I register for the UIKeyboardWillHideNotification notification, I do not get the callback keyboardDisappeared:(NSNotification*)note
I am trying to hit the "down keyboard button" on my keyboard but nothing is firing.
This is how I register:
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(keyboardDisappeared:) name:UIKeyboardWillHideNotification object:self];
And this is my callback:
- (void)keyboardDisappeared:(NSNotification*)note
{
NSLog#("called");
}
Also this method :
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
is not getting called. But this one:
- (void)textViewDidBeginEditing:(UITextView *)textView
IS getting called...
Any thoughts or suggestions?
Thanks,
You need to implement the UITextField delegate method, textFieldShouldReturn:, and have your text field resign first responder status in that method.
I have a modal view that with a UITextView, and the user can enter some text (or not) and close the modal view. There is no point of dismissing the keyboard as it does not dismiss the modal view (this is on purpose), and the UITextView without the keyboard just looks silly.
Is there a way to hide or remove the "Dismiss keyboard" key from the keyboard?
You can't hide or remove the key, but you can disable it using the UITextViewDelegate protocol:
- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
return NO;
}
If UIKit forces the responder to resign despite the delegate (doubtful, but I haven't looked closely at the call stack), you can force the keyboard to stay up by observing the UIKeyboardDidHideNotification and setting the first responder back to the UITextView: [myUITextView becomeFirstResponder]
Protocol method doesn't help.
As Answerbot suggested one should listen to keyboard notification.
- (void)onIpadViewWillAppear
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(showIpadKeyboard) name:UIKeyboardDidHideNotification object:nil];
}
- (void)onIpadViewWillDisappear
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)showIpadKeyboard
{
[myTextField becomeFirstResponder];
}
This works and looks beautifully.
How can I interact with the button "hide keypad"
In IPad numeric pad.
I need to add validation for this button.
Or how I can switch off this button?
This is not the delegate method for the keyboard hide button .But I think You can solve this by adding the following code to you .m file
1.Add the following code to your viewWillAppear function
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:)
name:UIKeyboardDidHideNotification
object:nil];
2.Add the following code to viewWillDisappear function
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
3.Declare function in .h file
-(void)keyboardWillHide:(NSNotification*)notify;
4.Define function in .m file
-(void)keyboardWillHide :(NSNotification*)notif
{
//Add the code for What you wish to do after the key board hide.
}
Use this to get the moment when the user hits that button
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
//your code here
return YES;
}