Problem showing/hiding keyboard in iPhone app - iphone

In my iPhone app, I am facing some problems related to keyboard show/hide behavior.
I have three text fields; when the third text field is clicked, I want to display a UIPickerView and hide the keyboard for that text field. That I can do.
Now the problem is that, if the keyboard of either first or second text field is visible, and I click on the third text field, the picker becomes visible, but it appears behind the keyboard (it is only behind the keyboard of the first or second text field).
So what should I do to make the picker visible by itself and not to display any keyboard at that time?
Here is the code:-
-(void) textFieldDidBeginEditing:(UITextField *)textField{
if (textField==thirdTextField) {
[scroll setFrame:CGRectMake(00, 48, 320, 160)];
[scroll setContentSize:CGSizeMake(320,335)];
[picker setHidden:NO];
[tool1 setFrame:CGRectMake(0,180,320,44)];
[tool1 setHidden:NO];
[self.picker reloadAllComponents];
[firtTextField resignFirstResponder];
[secondTextField resignFirstResponder];
[thirdTextField resignFirstResponder];
}
else {
[scroll setFrame:CGRectMake(00, 48, 320, 200)];
[scroll setContentSize:CGSizeMake(320,335)];
[tool1 setHidden:NO];
[tool1 setFrame:CGRectMake(0,220,320,44)];
}
}
the problem is like

Keep three textfields as member of the controller.
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField == 3rdTextField){
[self.firstTextField resignFirstResponder];
[self.secondTextField resignFirstResponder];
[self.thirdTextField resignFirstResponder];
}
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if(textField==3rdTextField){
[firstTextField resignFirstResponder];
[secondTextField resignFirstResponder];
}
else if(textField==secondTextField){
[firstTextField resignFirstResponder];
[3rdTextField resignFirstResponder];
}
else if(textField==firstTextField){
[secondTextField resignFirstResponder];
[3rdTextField resignFirstResponder];
}
return YES;
}
Hope this will help you.

Call
[yourTextField resignFirstResponder]
on all other textfields to make their keyboard disappear.

use the resignFirstResponder methods and the text fields. [textField resignFirstResponder] that will hide the keyboard.

Then use a Notification when keyboard becomes visible and have a boolean called isPickerVisible.When picker becomes visible set isPickerVisible to TRUE.
In the keyboardDidShow method check whether picker is visible or not. If it is visible then hide it.
Adding a notification:[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardDidShow:)
name:UIKeyboardWillShowNotification
object:nil];
And the method...
- (void)keyboardDidShow:(NSNotification*)notif {
if(isPickerVisible) {
[self hidePicker];
}
}
Hope this helped...

In - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField method use resignFirstResponder for all the textfield except the third textFied:-
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField==thirdTextField)
{
[firstTextField resignFirstResponder];
[secondTextField resignFirstResponder];
[textField resignFirstResponder];
[self showPickerView];
}
return YES;
}

Related

UItextField Delegate not working

In my iPad app I have two textfields. One displays the normal, default textfield and the other should display a picker as its input view.
Problem is, once I use the txt1 which displays default keyboard and then when I touch the 2nd textField the txt1 keyboard is staying visible.
I have also written [txt1 resignFirstResponder]; [txt2 resignFirstResponder]; while displaying the picker.
I have checked the txt1 IBOutlet connection and the delegate assignment, those seem to be correct.
What am I missing?
Write the following code :
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == txt1)
{
return YES;
}
else
{
return NO; // Write the code for displaying UIPickerView instead of the Keyboard.
}
}
Hope this might solve your issue......
txt2.userInteractionEnabled = NO;
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == txt1)
{
[txt2 resignFirstResponder];
// code for Hide Picker
return YES;
   }
else {
// [txt2 resignFirstResponder];
[txt1 resignFirstResponder];
// code for go in picker
return YES;
}
}
for more information
You have to implement below method to resign Keyboard......
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
Have u implemented this method ??
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
In your viewDidLoad method write this,
txt2.inputView = pickerView;
and other resignFirstResponder codes should be placed correctly , by this on Tapping txt2, you will directly get pickerview instead of Keyboard.
did you implement the delegates property of UITextFieldDelegates to in the header file, if not do that and check

How can I make the keyboard of other text field disappear while accessing other text field

I have two text fields in my view. I did it using IB. in second text field i am using the action sheet
After entering the text in textField1 I am in text Field-2.In second text field i am using the action sheet with a picker to select the date. so i resigned the textfield -2 keyboard before opening the action sheet. after i dismiss the action sheet when i tried to resign the keyboard it is not returning.
i used
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textfield1 resignFirstResponder];
return YES;
}
to resign the textfield1 ..
- (void) viewDidLoad
{
//don't forget to add <UITextFieldDelegate> in your .h
firstTextField.delegate=self;
secondTextField.delegate=self;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField.tag==2)
{
//Here you can call function to view your datepicker
return NO; //Will not open keyboard for second textfield.
}
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
You have return current textField textFieldShouldReturn method change your textFieldShouldReturn metod like below
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
You need to Give the tag for TextField,
Within this method,
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField.tag == 2)
{
[textField1 resignFirstResponder];
// your action sheet code here
}
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textfield resignFirstResponder]
return YES;
}
Set tag to every text fields and check them in
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if([textfield.tag == 1])
{
[textFieldFirst resignFirstResponder];
}
else
{
// your action sheet code here
}
return YES;
}

UITextField ResignFirstRespond not working in iphone?

I am designed one form with four UITextFields. First One for entering numbers, Second for entering name, third for choosing date and last one for choosing time. First textfield using Numberpad it will hide by using done button on the keyboard. If the user when enter into second (Name textfield) from first (number textfield) the first keyboard hide perfectly. If the user entering name and select date textfield am showing the datepicker in Actionsheet, when the user pick the date and hit done/cancel button i hide the actionsheet. But, the name textfield keyboard don't dismiss from the screen. I have tied below code, it is not working. Can anyone please suggest the idea for this clarification? Thanks in advance.
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == numberTextfield)
{
[textField setInputAccessoryView:keyboardToolbar];
}
else if(textField == nameTextfield)
{
}
else if(textField == dateTextField)
{
[self showdateActionSheet];
[nameTextfield resignFirstResponder];
[dateTextField resignFirstResponder];
}
else if(textField == timeTextField)
{
[timeTextField resignFirstResponder];
[nameTextfield resignFirstResponder];
}
}
- (BOOL) textFieldShouldReturn:(UITextField *)textField // If the user select Return key it is dismissing fine
{
[nameTextfield resignFirstResponder];
return YES;
}
-(BOOL) textFieldShouldEndEditing:(UITextField *)textField
{
[nameTextfield resignFirstResponder];
return YES;
}
-(void) DateDone
{
[nameTextfield resignFirstResponder];
}
-(void) timeDone
{
[nameTextfield resignFirstResponder];
}
Gopinath. Please try my following code,
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField == dateTextField )
{
[nameTextfield resignFirstResponder];
[self showdateActionSheet];
[dateTextField resignFirstResponder];
}
else if( textField == timeTextField)
{
[nameTextfield resignFirstResponder];
[self ShowTime];
[timeTextField resignFirstResponder];
}
return YES;
}
I am sure i will help you.
Just do this:
self.view.editable = NO;
Link: How can I programmatically link an UIView or UIImageView with an event like “touch up inside”.

How to unhide the keyboard of the current active textbox?

I have an IBAction linked up to EditingDidBegin on all my UITextFields, so why isn't the following code working when the UITextFields are tapped on?
-(IBAction)keyboardShouldShow
{
[self becomeFirstResponder];
NSLog(#"Keyboard Showing");
}
Also bear in mind that the keyboard will not show unless this code is added because of other code I have in my project file.
Thanks
your self is not your textfield.try to change the method to this and relink it to editingdidbegin.
-(IBAction)keyboardShouldShow:(UITextField*)sender
{
[sender becomeFirstResponder];
NSLog(#"Keyboard Showing");
}
HIH
Because self is your view controller, not the UITextField.
Use the UITextFieldDelegate method:
- (void) textFieldDidBeginEditing:(UITextField *)textField {
if ([textField isKindOfClass:[UITextField class]]) {
[textField resignFirstResponder];
NSLog(#"Keyboard Showing");
}
}
And if you want to use your own method, be sure to pass the UITextField as a parameter.
Change the method to something like:
-(IBAction)keyboardShouldShow:(id)sender {
if ([sender isKindOfClass:[UITextField class]]) {
[sender resignFirstResponder];
NSLog(#"Keyboard Showing");
}
}

After becomeFirstResponder textField doesn't send events to delegate

can anybody help me in such situation:
I have SigninController class with two textFields (as Outlets) txtLogin and txtPassword:
when I filled txtLogin, I call [txtPassword becomeFirstResponder] to pass input focus to next field (return button works fine in txtLogin), but Return button doesn't work in txtPassword and I can't dismiss keyboard in this case. What did I write wrong ?
Example code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == txtLogin) {
[txtLogin resignFirstResponder]; //Works as I think
[txtPassword becomeFirstResponder]; // txtPassword gets focus
} else {
[self signinClick]; //Never enter here
}
return YES;
}
- (IBAction)signinClick
{
NSLog(#"Signin Clicked");
[activityIndicator startAnimating];
[txtPassword resignFirstResponder];
..........
}
It seems you have forgot to set the delegate of txtPassword correctly.
specify
urtextfieldobject.delegate=self;
then urViewcontroller.h
#interface urViewcontroller
make sure both of them