Resign keyboard when leaving textfield - iphone

Hey, I have created a textfield within two custom cells. One textfield shows the standard keyboard and the other the shows a pickerview when entered. The problem I have is when I move from the keyboard to pickerview textfield without clicking the "return" button on the keyboard, the keyboard doesn't resign. However when I do it using the "return" the keyboard resigns. Am using:
- (void)textFieldDidEndEditing:(UITextField *)myTextField{
[myTextField resignFirstResponder];
}
and can't work out why this isn't working.
Thanks,
William

-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == pickertextfield)
{
[textfield1 resignFirstResponder];
[pickertextfield resignFirstResponder];
}
return YES;
}

Does your view controller adopt <UITextFieldDelegate>? Is it hooked up as the delegate of your text fields?

Try using [self.view endEditing:YES]; before showing the pickerview and see it it helps.

Related

How to dismiss keyboard on second time selecting first textfield?

I'm trying to dismiss keyboard on textfield did begin editing.
First time selecting that textfield works fine, But in second time after resigning second textfield first textfield doesn't resign keyboard.
I tried hard but not get result
Can any one help me.
Thanks in advance.
You can hide keyboard by own method.
For Eg.
-(IBAction)hideKeyboard:(id)sender {
if (sender == txt1) {
[txt2 becomeFirstResponder];
}
else if (sender == txt2) {
[txt2 resignFirstResponder];
}
}
Bind both of textfields with 'Did End On Exit' method in xib.
After resigning first, it'll focus on 2nd. Then after resigning 2nd, keyboard will be dismissed. you can continue with many textfields in this manner.
It'll work definately.
Thanks.
Implement textField's delegate to all the textFields to your class.
And use this one:
- (BOOL) textFieldDidBeginEditing:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
try this...
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if (textField == yourTextfield1) {
[textField resignFirstResponder];
}
}

UITextfield keyboard resign

in my uitableview in each cell I'm having uitextfield when user edits the textfield and after pressing any other button on the screen the Keyboard is not resigning. I did the following in textfield delegates
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
textfieldInCell = textField;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
textfieldInCell=nil;// this is the ivar i am using for each textfield in cell.
return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
textfieldInCell=textField;
// do the process...
textfieldInCell=nil
}
I am also calling the shouldReturn delegate function once the user tapping on any other button but the keyboard is not resigning. Where am I going wrong?
Confirm that you bind the delegate of each textfield that you create with the view controller and add one line of code in textfield did end editing :-
-(void)textFieldDidEndEditing:(UITextField *)textField
{
// add the following line
[textField resignFirstResponder];
textfieldInCell=textField;
// do the process...
textfieldInCell=nil
}
have you bind delegate of textfield with your controller? or did you check textFieldShouldReturn calling or not?
i think, binding is missing wit view controller in your case.
thanks
add a line in your tableview where you are adding textfield.
<YOUR_TEXTFIELD>.delegate = YES;
Enjoy Programming
first check that you give the delegate or not and give the delegate to UITextField after that when you call the method of button at that time resign this textfield like bellow...
-(IBAction)yourButton_Clicked(id)sender{
[yourTextField resignFirstResponder];
////your code write here
}
you must try to assign tag value to textfield then in should return method you used that tag to hide the keyboard like this (if you assign the tag -1 then)
-(void)textFieldDidEndEditing:(UITextField *)textField{
if(textField.tag==-1){
[textField resignFirstResponder];
}
}

i have used keypad in my program its not working

I have two textfields which are of type UITextField.
I have two buttons click and cancel.
The idea is to enter two numbers and it will navigate to next view. This View should display those two numbers.
The problem is if I click on the textfield one then the keypad is responding; when I click return it does not jump to the next field.
-(BOOL)textFieldShouldReturn:(UITextField *)textField{[textField resignFirstResponder];return YES;}
You need to connect UITextFiled Delegate from nib or programeticuly like this image:
or
other way is programmatic like in your viewDidLoad method or viewWillAppear method:
Yourtxtfild.delegate = self;
EDIT
for jumping AnotherView Use this textfiled delegate method:-
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
//you can set your textfiled string in to globle Variable and use it in another viewController
YourViewCntroller *objViewController = [[YourViewCntroller alloc] initWithNibName:#"YourViewCntrollernib" bundle:nil];
[self.navigationController pushViewController:objViewController animated:YES];
}
You have to set the delegate of the textfield as the object of the class where you have written the textFieldShouldReturn: method.
#Ragavan : You are just resigning the first textfield, but you are not making the other textfield to respond. So, use the code below as reference to make it work.
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField1 resignFirstResponder];
[textField2 becomeFirstResponder];
return YES;
}

UITextField always resignFirstResponder

I am using a UIPickerView and I want my keyboard to never show up for some of my UITextFields. When I call resignFirstResponder on the UITextField after it is touched it doesn't make the keyboard go down.
- (IBAction) txtFieldClicked:(id)sender {
[txtField resignFirstResponder];
}
For each text field where you don't want to be able to show the keyboard, do:
[textField setUserInteractionEnabled:NO];
You can also check a corresponding block in the Interface Builder UI. This prevents the text field from receiving the touch event that would otherwise trigger it to display the keyboard.
Set text field delegate and implement its delegate methods
See UItextFieldDelegate
If you dont want the keyboard to pop up, return NO for all those text fields here
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if([textField isEqualTo:self.myTextField]) {
return NO;
}
return YES;
}

iPhone: Resign Keyboard with Done button action with XIB

hi i am working on UITextview
how to Resign Keyboard, after keyboard "Done button" click Action, which XIB
Thank you
hi if you want answer for, Resign the keyboard of UITextview with default "Done" button on keyboard, then this is answer for that
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text {
// Any new character added is passed in as the "text" parameter
if([text isEqualToString:#"\n"]) {
// Be sure to test for equality using the "isEqualToString" message
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added
return NO;
}
// For any other character return TRUE so that the text gets added to the view
return YES;
}
i followed this to resign keyboard of UITextview, if there is any concern inform me
Thank You
Create an IBAction and in IB hook it up to the UITextfield's DidEndOnExit event. Then call the [textViewName resignFirstResponder] to make the keyboard go away.
Alternatively, try using [self.view endEditing:YES] in the IBAction.
To assign the action to the Done button of a keyboard:
In these examples, myTextView is a UITextView that is defined in the header and connected in Interface Builder.
-(BOOL)textViewShouldReturn:(UITextView*)textView {
if (textView == myTextView) {
[textView resignFirstResponder];
}
return YES;
}
To assign it to an external button:
Be sure to define an IBAction in your header, then in Interface Builder, connect the button to this action for touchUpInside:
.h
-(IBAction)dismissKeyboard:(id)sender;
.m
-(IBAction)dismissKeyboard:(id)sender {
[myTextView resignFirstResponder];
}
Call resignFirstResponder on the textview that has focus in order to dismiss the keyboard.