Remove the "Dismiss keybard" key from a UITextView's keyboard on iPad - objective-c

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.

Related

Replace textfield's keyboard on uipopover in UIwebview

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
}
}

How to find out that keyboard down arrow key pressed, programmatically

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

NSWindow is not receiving any notification when it loses focus

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;
}

Not getting Keyboard Hide notification

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.

Calling UIKeyboard method on UITextView and not UITextFields

I have view with a UITextView for comments on the bottom. Since its on the bottom of the page, whenever someone edits it, a method is called to shift the view of the page, so that you can still see the comment box. My problem is that the same method also gets called when user are editing UITextFields.
Here's what I have. First I declare a notification:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:self.view.window];
Then the method itself
- (void)keyboardWillShow:(NSNotification *)notif{
...
}
My first thought was to add a condition, to check and see if the object was a TextView, and only then execute the code. But since I am not passing the object to the method, is there anyway to tell the method what type of object I am dealing with
Text fields and text views also send notifications. In the textFieldShouldBeginEditing and the textViewShouldBeginEditing implementations you could set a flag that you can read in your implementation of the keyboardWillShow method -- the keyboard notification is sent after the text field or text view notifications.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
self.sender = #"text field";
return YES;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
self.sender = #"text view";
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:self.view.window];
}
- (void)keyboardWillShow:(NSNotification *)notif{
NSLog(#"%#",self.sender);
}