I have three text fields in one view controller and when i do the method to dismiss the keyboard for all three text fields, the view controller doesn't come out.
- (void)viewDidLoad
{
[super viewDidLoad];
self.namesuite.delegate = self;
self.createpassword.delegate = self;
self.createname.delegate = self;
// Do any additional setup after loading the view.
}
I also have the textFieldShouldReturn function.
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
This is my button function to send me to the view controller that has the text fields.
- (IBAction)createaccount:(id)sender
{
[self performSegueWithIdentifier:#"thirdsegue" sender:sender];
}
This will help. Try this:
[self.view endEditing:YES];
Hope this helps .. :)
You should try this control (TPKeyboardAvoiding) and get ride of resign and scrolling issues. Its a generic solution.
Try:
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.namesuite resignFirstResponder];
[self.createpassword resignFirstResponder];
[self.createname resignFirstResponder];
return YES;
}
or
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == self.namesuite)
{
[self.namesuite resignFirstResponder];
}
else if (textField == self.createpassword)
{
[self.createpassword resignFirstResponder];
}
else if (textField == self.createname)
{
[self.createname resignFirstResponder];
}
return YES;
}
Related
I have two textfields as emailTextField and passwordTextField.
I have written the following textfield delegate methods for moving one text field to another:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == emailTextField) {
[textField resignFirstResponder];
[passwordTextField becomeFirstResponder];
} else if (textField == passwordTextField) {
[textField resignFirstResponder];
}
return YES;
}
When I click to next button after entering email then it will go to password textfield but within a fraction of a second, the keyboard will disappear.
What is the solution for this? Is there a mistake in the code?
Try this
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == emailTextField) {
[passwordTextField becomeFirstResponder];
} else if (textField == passwordTextField) {
[textField resignFirstResponder];
}
return YES;
}
I have two text fields. I am using this code in textFieldDidBeginEditing, but it's not dismissing the keyboard.
-(void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField==textFieldOne)
{
}
else if (textField==textFieldTwo)
{
[[IQKeyboardManager sharedManager]resignFirstResponder]
}
}
This might help Try
-(void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField==textFieldOne)
{
}
else if (textField==textFieldTwo)
{
[self.view endEditing:YES];
}
}
How to I go from one textfield to the next with the next button?
Here is my code that will not work:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == self.amountField) {
[theTextField resignFirstResponder];
} else if (theTextField == self.businessField) {
[self.memoField becomeFirstResponder];
}
return YES;
}
Call [textField resignFirstResponder]; before your first conditional
there are many solutions but I prefer this one:
[self.firstTextField addTarget:self.secondTextField action:#selector(becomeFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit];
[self.secondTextField addTarget:self.thirdTextField action:#selector(becomeFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit];
just set it up in viewDidLoad
In my class,i have more then 30 UITextField and one UIButton. When I click the uibutton i need to resign the keyboard of all uitextfield without giving resignfirstresponder to all 30 uitextfields.
My code like this
-(IBAction)click:(id)sender
{
[txt1 resignFirstResponder];
[txt2 resignFirstResponder];
[txt3 resignFirstResponder];
[txt4 resignFirstResponder];
.
.
.
[txt30 resignFirstResponder];
}
I need simple way to resign UITextField keyboard
Every view has endEditing property , try simply this
[[self view] endEditing:YES];
and let me know whether it works for you or not ..
UITextField *currentTextField;
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
currentTextField = textField;
}
-(IBAction)click:(id)sender
{
[currentTextField resignFirstResponder];
}
Then simply in the method below add
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
or
in the delegate method
-(void)textFieldDidEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
}
-(void)KeyboardHide
{
[txt1 resignFirstResponder];
....
....
[txt30 resignFirstResponder];
}
-(IBAction)click:(id)sender
{
[Self KeyboardHide];
}
I have two fields, fldPassword and fldUsername. With this code (and a self delegate in the view did load), I would expect the return key to dismiss at both of the text fields. However, it only does it on the first. What am I doing wrong?
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (fldPassword == self->fldPassword) {
[fldPassword resignFirstResponder];
} else if (fldUsername == self->fldUsername) {
[self->fldUsername becomeFirstResponder];
}
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
[theTextField resignFirstResponder];
return YES;
}
in your .h file add delegate method :
#interface YourViewController : UIViewController<UITextFieldDelegate>
then it will work for both textfields.
hope this helps u.
You are dismissing only the fist one, try this:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (fldPassword == self->fldPassword) {
[fldPassword resignFirstResponder];
}
if (fldUsername == self->fldUsername) {
[self->fldUsername resignFirstResponder];
}
return YES;
}