IPad keyboard "Hide button" - objective-c

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

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

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

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

iPad : How to know Return key of iPad keyboard is pressed ? Please check image

I want to know that which method will be called when the following key is pressed.
I want to start action on above key press.
How do I know this is pressed ?
Observe the UIKeyboardDidHideNotification notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
And...
- (void)keyboardDidHide:(NSNotification *)aNotification {
}
You can also change it to UIKeyboardWillHideNotification if you need to be notified BEFORE the keyboard starts to disappear.
That's not a return key. Return key is the one above it. That's simply a button that dismisses the keyboard and you can't recognize it via standard text input methods. You need to register for UIKeyboardWillHideNotification notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
and implement that method:
- (void)keyboardWillHide:(NSNotification *)notification
{
// do whatever you want to do when keyboard dismiss button is tapped
}
Not sure if it's exactly what you are looking for, but you can try using notifications. Don't have Mac nearby atm, so just copy-pasting the code from github. I have that code in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
and then 2 methods:
- (void)keyboardWillShow:(NSNotification *)notification {
}
- (void)keyboardWillHide:(NSNotification *)notification {
}
Hope it helps
Use keyboard hide UIKeyboardWillHideNotification notification.
Example.

how to manage scrolling of table view containing text fields

When I try to scroll and edit the cells at the bottom of the UITableView, I can't manage to get my cells properly positioned above the keyboard. Actually keyboard hides half of the table view.
Also i created a custom cell class separately for my cells. So text fields delegates are available on that class only. i can't use them in my table biew's view controller
I have seen many answers talking about changing view sizes,etc... but none of them has worked nicely so far.
could anybody help me with this with a piece of code
An easier way to do this now (don't know how long this has been available): if you're overriding viewWillAppear, make sure to include at the top
[super viewWillAppear:animated];
I was all set to start listening to keyboard events and setting and removing constraints and just this one line eliminated all that other code.
You want to adjust the scrollView component of the UITableView. Set your view controller to respond to Keyboard notifications. Like this :
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
Then create a keyboardWillShow: function and adjust the tableview by manipulating the tableView.scrollview.contentOffset (it might be tableView.contentOffset im not near xcode). Make sure you make a keyboardWillHide function to adjust it back to 0,0.