How to call method on return key and also on ipad down arrow key - iphone

I have method for textfield animation which is running on after resignfirsrresponder i want that method also be called when user presses down arrow of the ipad which hides keyboard any idea how to do this. thanks.
I have added screenshots the button beside ABC text button i when we press that button normally keyboards hides i want to call animation on that button click.

For Ipad down arrow key You can use notification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide)
name:UIKeyboardWillHideNotification
object:nil];
-(void)keyboardWillHide
{
//call when key board hides
}

You can call the textfield animation method in any one of the following UITextFieldDelegate methods
- (void)textFieldDidEndEditing:(UITextField *)textField {
}
or
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
return YES;
}

just write your code inside
- (void)textFieldDidEndEditing:(UITextField *)textField {
}
And don't forget to bind textfield delegate and write <UITextfieldDelegate> in .h file

if you want use done button on key board take one view with done button and write this method
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[textField setInputAccessoryView:self.doneView];
}
and then give following action to that done button
-(IBAction)doneButtonPressed:(id)sender
{
[currentTextField resignFirstResponder];
}

Related

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

UITextField text change callback

I have a UITextField named textFieldInput and some button. Somehow I disable the input view so that if anyone tap in the texField no keyboard will show. I am adding text when a button is pressed programmatically. And I want to catch this changes. I want to call a function when the text of textField will change. How Can I do that?
I tried by adding following function
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)replacementStr {
// some my code
return YES;
}
But this does not work. this only calls when i tap on the textField.
I also tried by adding following in my viewDidLoad function
[textFieldInput addTarget:self action:#selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
this also doesn't work.
How can I do this?
Thanks.
Register notification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(textChanged:)
name:UITextFieldTextDidChangeNotification
object:YOUR_TEXT_FIELD];
shouldChangeCharactersInRange:
this will work only when you set its delegate with the controller which implements this method. one other way is:
add these line viewDidLod
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:#selector (handle_TextFieldTextChanged:)
UITextFieldTextDidChangeNotification
object: textFieldInput];
and implement handle_TextFieldTextChanged:
- (void) handle_TextFieldTextChanged:(id)notification {
// write your logic here.
}

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.

Resign keyboard when leaving textfield

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.

make return button on keyboard perform an action

I have a searchbox. I want to make it so when the user pushes search on there keyboard it performs and IBAction. How can i link that key to the -(IBAction)Method.
There one delegate method which is fired when search button is pressed
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
//CALL YOUR IBACTION METHOD HERE
}
-Happy Coding
(BOOL)textFieldShouldReturn:(UITextField *)textField{
[self yourButtonName:nil];
}