Hide the default keyboard [duplicate] - iphone

This question already has answers here:
how to resign keyBoard as a firstResponder from a textView?
(4 answers)
Closed 9 years ago.
I am pretty new in this programming, I am making a app in Xcode 4.6 with custom keyboard.
I made the keyboard and it is working great but I need to disable the default keyboard when I hit the text box, how do i do that? Like I said I am new to this so any help would be great.

So, you have two choices.
1- UITextField has a delegate methods called
-(void)textFieldDidBeginEditing:(UITextField *)textField this is the method when you hit your textField. So you need to hide your default keyboard here.
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[self.yourTextField resignFirstResponder];
}
2- There is a notification called UIKeyboardWillShowNotification which is posted immediately to the display of keyboard. So, You can use NSNotificationCenter to do your job when you received notification. So, in your viewDidLoad method :
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
then implement your selector.
-(void)keyboardWillShow:(id)sender
{
[self.yourTextField resignFirstResponder];
}
I've tested both of them, i think they are working well.
I hope that helps.

Do you just want to hide the keyboard or want to show your custom keyboard also? To show your custom keyboard instead of default one, use inputView property of textfield and set your keyboard to it. textField.inputView = customKeyBoard.

Related

Default Keyboard appears in iPhone instead of my custom keyboard

I am making a custom keyboard in my app for iPhone. But when I tap on the UITextField the default keyboard also appears. Where as I want only my keyboard to pop-up on the screen. How do I stop default keyboard from appearing on the screen?
You can try the following line of code
your_TextField.inputView = your_CustomKeyboard;
I am not confirm that it will work for your custom Keyboard i tried this to use a datepicker as inputview and it did worked so it may help you
I got the answer to my question. Since I am new here i cudnt post an answer b4 8 hrs after my own question post. And yes Tejeshwar Gill, Thanks for the response and my solution matches your approach. Thanks again.
I used the NSNotificationCenter to notify me when the keyboard appears. I had used this method to resize my tableview when the keyboard appears, but that was quite some time before. So it didnt click me instantly then.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(hideKeyboard:)
name:UIKeyboardWillShowNotification
object:nil];
You need to hide the default keyboard inorder to show your custom keyboard. So use this:-
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil]; and in the method keyboardDidHide: , add [keyboard resignFirstResponder].

Can I disable the keyboard from showing in a UIWebView?

Is it possible to disable the keyboard from showing when a webpage element is selected inside a UIWebView?
Register for a keyboard notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
And then you can stop it from showing by placing the following code in keyboardWillShow :
UITextField *dummyTextField = etc.
//Basically, create a dummy uitextfield that you never show.
//I can't remember all the syntax :)
[dummyTextField becomeFirstResponder];
[dummyTextField resignFirstResponder];
//Keyboard should be gone. Hoorah!
Not sure 100% if this will work without flaws. If the keyboard starts to animate then hides itself again, you could use
[UIView enableAnimations:NO];
If the keyboard doesn't like being resigned while it's showing then you could try changing the inputView property of the dummy textField to some dummy UIView instead.
Hopefully this should get you somewhere!

How to hides the keyboard when we use the UITextView?

Iam developing one application.In that i use the textview.But when we click on textview,or completion of entering the text into textview,textview delegate methods are not fired.Ias writtent he textview.delegate=self also.But they are not firing.So pleas etell me how to solve this one
The UITextViewDelegate methods do not handle dismissal of the keyboard: you must do that yourself, by calling:
[textView resignFirstResponder];
This will then trigger the textViewShouldEndEditing:(UITextView *)textView delegate method. What you need to do is call the resignFirstResponder method in response to whatever actions you require - if this is tapping outside the text view you'll need to create a gesture recognizer / button / whatever to pick up that tap and call resignFirstResponder.
You can also use Keyboard notifications like:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow)
name:UIKeyboardWillShowNotification object:nil];
and in -(void) keyboardWillShow {} set [myTextField resignFirstResponder];
hope this helps.

UIKeyboardWillShowNotification, UIKeyboardWillHideNotification and NSNotificationCenter problem between iOS versions

I have several UITextFields on my view (each inside a UITableViewCell). When the keyboard is fired from any of the textfields, I need to make some animations, mainly to change the frame of the UITableView. The same must happen when the keyboard will hide.
I have done the animation, so this is not the issue here.
Now, I use NSNotificationCenter to catch displaying/hiding of the keyboard:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
The problem is when the keyboard is visible (a textfield is used) and I press inside another textfield. Usually for this thing keyboard will not hide, but will stay visible.
It works fine in iOS 4, but the problem comes in 3.1.3 (this is the version that I can test - possibly any version below 3.2). In versions older than 3.2 changing focus from a textfield directly to another textfield will fire the UIKeyboardWillHideNotification and UIKeyboardWillShowNotification.
Anyone knows a way to perform some animation when the keyboard will really show/hide, without the NSNotificationCenter?
Or how can I overcome this issue with versions lower than 3.2?
Thanks.
What you can do is set the textfield's/textview's delegate to the current view controller and implement these 2 methods
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
_keyboardWillHide = NO;
return YES;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
_keyboardWillHide = NO;
return YES;
}
After that in your method that get's triggered by the UIKeyboardWillHideNotification notification you can do something like
if (_keyboardWillHide) {
// No other textfield/textview was selected so you can animate the tableView
...
}
_keyBoardWillHide = YES;
Let me know if that works for you.
Rather than avoid the notifications, you can set an NSTimer for 0.1 second to do your animations in one, and in the other, cancel the timer, that way if you get UIKeyboardWillHide and UIKeyboardWillShow both at once, you'll get a chance to cancel the timer. If you don't get both, the timer will reach zero and the animations will be carried out.
Consider using the UITextFieldDelegate protocol. The method textFieldShouldBeginEditing: will fire off before the notification and it will fire off everytime you go into the text field.

Keyboard won't dismiss when popover closes on iOS 3.2

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
[self dismissFirstResponder];
return YES;
}
-(void)dismissFirstResponder {
[nameField resignFirstResponder];
[descriptionField resignFirstResponder];
[helpField resignFirstResponder];
}
I have tried loads of different things, but the keyboard just isn't going down:
I checked to see if my outlets were hooked up correctly in Interface Builder
I put breakpoints inside the 2 methods to check they were being called at the appropriate times, and they were. Those 3 Text Fields are the only ones in the app.
What happens: The popover gets dismissed but the keyboard stays up.
I would really appreciate some help on this matter. It might be a known bug on iOS 3.2, if so any workarounds would be gratefully accepted. Thanks
Make sure the delegate for UITextView the UITextField is assigned
Then call the following method to dismiss any keyboard activity from the view.
[self.view endEditing:YES];