how to hide keyboard on ipad while pressing arrowkey - iphone

In iPad we have
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textFieldOne resignFirstResponder];
[textFieldTwo resignFirstResponder];
return YES;
}
but also we can close keyboard on arrow key so whcich that method of arrow key on which we can show something
here is the screenshot

There isn't any function which gets called when "Hide Keyboard" button is clicked on iPad. If you want to perform any action when keyboard goes down. You can either use following function :
- (void)textFieldDidEndEditing:(UITextField *)textField
Or, you can use keyboard notifications i.e. UIKeyboardWillHideNotification.

Related

Unable to resign keyboard when using PopOver

In my iPad app there are 3 textboxes where i am using popoverview controller on second text box.
here their are 2 cases
In First Case:
As i finish editing the first textbox and click the next button on keyboard that time the keyboard is resigning perfectly and the popoverview controller is opened on second text box.Here i had written the code when the next button of the first textbox click at that time the second textbox should became FirstResponder.
In Second Case:
Here the actual problem,
When i finish editing the first textbox and directly touches the second textbox without clicking the next button on keyboard, that time popoverview controller menu is opened on second textbox and the keyboard is unable to resign , the keyboard is strucking over their my code for resigning the keyboard is not working.
Write your code which you used on NEXT button event of Keyboard in this bellow method...
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
if (textField == yourFirstTextBox) {
// write your code here
}
return YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textfield
{
if ([textfield tag]==yourtextfieldtag)//set tag for your textfield
{
[yourfirsttextfield resignFirstResponder];
[yoursecondtextfield resignFirstResponder];
.
.
.
//Write all textField with resignFirstResponder
}
}
Here is the way you can handle your SoftKeypad
Handling Soft Keypad in iPhone Tutorial
There are three simple ways to handle keypad here
Keypad go back when Button clicked.
Keypad go back when user click on Return or Done button on keypad.
Keypad go back when user Touch on Background screen/view.
Just follow 3rd way in you case.
What you need to do is just crate a method in which call
method for the desired text field.
and Updated Related UIView class to UIControl in Interface Builder.
as I have written all the information step by step to make it more easy and clear.
Here is the responsible code snip
- (IBAction)keypadGoBack:(id)sender {
[userNameTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
}
Hope this will help you.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField==yourTextField)
{
[self.view endEditing:YES];
// Write Your Popoverview Code / Extra Code
return NO;
}
return YES;
}
Here this method will get called when you will hit textfield.
And check the textfield with yourtextFieldName if its match..it will resign all keyboard.if there is more than one also..with the help of.
[self.view endEditing:YES];
And you can do Extra Code also For popoverview and return no means It will not give keyboard to that perticuler textField.
Thanks.

Hide IOS keyboard with multiple textFields

I have 2 textFields side by side, countryCodeTextField and cellphoneTextField
On countryCodeTextField. I have an action selectCountry that happens on Edit Did Begin on the countryCodeTextField
- (IBAction)selectCountry:(id)sender {
countryCodeTextField.delegate = self;
[countryCodeTextField resignFirstResponder];
Note that self implements the <UITextFieldDelegate>.
Problem is when user click's cellphone the keyboard is displayed if he clicks on countryCodeTextField the keyboard is never dismissed.
If the person clicks the countryCode first then the keyboard never appears(which is what I want).
Why isn't the keyboard hidden when the user clicks cellphoneTextField first and then countryCodeTextField?
If you don't want the user to be able to edit a particular UITextField, set it to not be enabled.
UITextField *textField = ... // Allocated somehow
textfield.enabled = NO
Or just check the enabled checkbox in Interface Builder. Then the textfield will still be there and you'll be able to update it by configuring the text. But as sort of mentioned in comments, users expect UITextFields to be editable.
Also, why are you setting the delegate in the IBAction callback? I would think you'd be better off doing this in Interface Builder or when you create the UITextField in code.
EDIT:
Ok - so you want users to be able to select the box, but then bring up a custom subview(s) from which they select something which will fill the box.
So set the UITextField delegate when you create it (as mentioned above) and implement the following from the UITextFieldDelegate protocol:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO;
}
to return NO. Note that if you are using the same delegate for both of your UITextFields, you will need to make this method return YES for the other field. For example, something like:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if (textField == countryTextField)
return NO;
return YES;
}
Hopefully this should stop the keyboard being displayed - and now you have to work out how to fire your own subviews, which I'd suggest doing via an IBAction (touch up or something perhaps). You'll have to test various things out here, but remember you're kinda corrupting the point of UITextField and maybe it'll work and maybe it won't, and maybe it'll break in the next iOS upgrade.
Okay, so first, I think you shouldn't be using a UITextField. I think you should be using a UIButton and have the current value showing as the button's title. However, if you have your heart set on it, I would use our good friend inputView, a property on UITextField, and set that to your custom input view (which I assume is a UIPickerView or similar.)
This has the added bonus of not breaking your app horribly for blind and visually impaired users, something you should probably be aware of before you go messing about with standard behaviour.
In your method :
- (IBAction)textFieldDidBeginEditing: (UITextField *)textField
call this :
[textField becomeFirstResponder];
and apply checks for the two fields i.e., when textField is the countryCodeTextField write :
[textField resignFirstResponder];
and call your method :
[self selectCountry];
In this method display the list of country codes.
So Your code will be :
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return YES;
}
- (IBAction)textFieldDidBeginEditing: (UITextField *)textField{
[textField becomeFirstResponder];
if (textField == countryCodeTextField){
[textField resignFirstResponder];
[self selectCountry];
}
}
-(IBAction)selectCountry{
//display the list no need to do anything with the textfield.Only set text of TextField as the selected countrycode.
}

Control should switch automatically after the user is done entering the text in UITextField

In my app i have two textfields and i want the control from one text field to switch to second control as soon as the user is done entering the values in the first textfield automatically.
Does anybody has any idea on this?
Thanks,
I assume "done entering" means the user hits return, ... button on keyboard.
UITextField has delegate with UITextFieldDelegate protocol. And here's method ...
- (BOOL)textFieldShouldReturn:(UITextField *)textField
... you can implement it in this way ...
...
self.myFirstTextField.delegate = self;
self.mySecondTextField.delegate = self;
...
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if ( textField == self.myFirstTextField ) {
// User hits return key on keyboard when editing first textfield
[mySecondTextField becomeFirstResponder];
} else if ( textField == self.mySecondTextField ) {
// User hits return key on keyboard when editing second textfield
// This simply removes focus from the second textfield and hides keyboard
[mySecondTextField resignFirstResponder];
}
return YES;
}
If "done entering" is not return, ... button on keyboard, you can implement this delegate's method ...
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
... to check UITextField's text when user did type.

Add 'Done' and 'New line' buttons on keyboard in iPhone application

I have created a window based application with a UITabbarController as the RootViewController.
In one of the tabs, i have provided UITextField and UITextView.
I want to provide two buttons on the keyboard itself:
Done - which will hide the keyboard.
Enter - for new line.
Please post your answer if anybody has some idea how to do it.
For the UITextField you can change the return key to a done key by setting the following:
targetTextField.returnKeyType = UIReturnKeyDone;
However, you won't be able to have a Enter and Done key at the same time without custom addition of views to the keyboard.
Also, to control the done behavior of the keyboard you have to implement a UITextFieldDelegate method:
targetTextField.delegate = self;
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
return YES; //dismisses the keyboard
}
I know you can set the returnKeyType for a UITextView but I'm not sure if you can manipulate the return key behavior.
You have a tutorial on how add subviews to the iPhone keyboard here :
http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/7350-adding-subviews-custimize-keyboard.html
Hope this helps,
Vincent
For some reason return YES; didn't work on its own. that worked for me :
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField.returnKeyType == UIReturnKeyNext) {
NSInteger nextTag = textField.tag + 1;
// Try to find next responder
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
// Found next responder, so set it.
[nextResponder becomeFirstResponder];
}
}
if (textField.returnKeyType == UIReturnKeyDone) {
[textField resignFirstResponder];
}
return YES; //dismisses the keyboard
}

Dynamically Changing Keyboard Type for a UISearchBar

I have an iPhone app that uses a UISearchBar and UISearchDisplayController. The search bar has three scope buttons. I would like the keyboard to be a numeric keypad when a particular scope button is selected, but be a default keyboard when any other scope button is selected.
I have implemented the UISearchBarDelegate selectedScopeButtonIndexDidChange:selectedScope method as follows:
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
switch (selectedScope) {
case DeviceIDScopeIndex:
searchBar.keyboardType = UIKeyboardTypeNumberPad;
break;
default:
searchBar.keyboardType = UIKeyboardTypeDefault;
break;
}
}
I know that the method gets called, and the right case gets triggered when the button in question is selected. But the onscreen keyboard doesn't change unless I tap the Cancel button to hide the keyboard, then tap the search field again to bring up the keyboard again.
Is there a way to get the keyboard to change itself while it's onscreen, or to programmatically hide it and then reshow it?
If you're using iOS 3.2 or newer, you can call:
[searchBar reloadInputViews]
and it switches immediately without hackery. At least this works for me on a UITextField. (I mention this because the resign/become first responder trick didn't work exactly right for me, but reloadInputViews did.)
Even though this is kind of a hack, this worked for me:
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope {
switch (selectedScope) {
case 0:
searchBar.keyboardType = UIKeyboardTypeNumberPad;
break;
default:
searchBar.keyboardType = UIKeyboardTypeDefault;
break;
// Hack: force ui to reflect changed keyboard type
[searchBar resignFirstResponder];
[searchBar becomeFirstResponder];
}
[searchBar reloadInputViews]
and
[searchBar resignFirstResponder];
[searchBar becomeFirstResponder];
both can work, but the second method have more side effect, change firstResponder, can trigger keyboard's notification, so may affect other logic which depends on the keyboard's notification, and affect the view's frame which depend on keyboard frame's change