Jayasabeen
Jayasabeen

Reputation: 136

Set UITextField delegate to all UITextFields and set view animation for few textfields

I have 13 text fields. I want to set view animation for only 4 text fields which will be displayed in bottom

Here is my code:

if (textField.editing != ((_GET_companyname)||(_GET_firstname)||(_GET_middlename)||(_GET_lastname)||(_GET_companyurl)||(_GET_streetaddress)||(_GET_postbox)||(_GET_code)||(_GET_phonenum)))
{
    NSLog(@"Entered in condition");
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        //Keyboard becomes visible
        [UIView beginAnimations:nil context:NULL];
        // [UIView setAnimationDuration:0.25];
        self.view.frame = CGRectMake(0,-200,self.view.frame.size.width,self.view.frame.size.height);
        [UIView commitAnimations];
    }
}
else
{
    NSLog(@"Entered else Part");
}

I need to set the below to all 14 textfields

-(BOOL) textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}

Upvotes: 0

Views: 108

Answers (2)

Bhargav Narkedamilli
Bhargav Narkedamilli

Reputation: 86

You can check these using tags - (void)viewDidLoad { [super viewDidLoad];

UITextField *textFiledName = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
textFiledName.tag = 0;
textFiledName.delegate = self;
[self.view addSubview:textFiledName];

UITextField *textFiledLastName = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
textFiledLastName.tag = 1;
textFiledLastName.delegate = self;
[self.view addSubview:textFiledLastName];

}

 - (BOOL)textFieldShouldReturn:(UITextField *)textField{
if (textField.tag == 0) {
  //No Animation
}else  if (textField.tag == 1){
   //Add Animation
}
return YES;

}

Upvotes: 0

Awesome.Apple
Awesome.Apple

Reputation: 1324

According to you if "_GET_companyname" is a IBOutlet of UITextField.

Then you should write something like this below

if ((textField != _GET_companyname)&&(textField != _GET_firstname)) // etc
{
    NSLog(@"Entered in condition");
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        //Keyboard becomes visible
        [UIView beginAnimations:nil context:NULL];
        // [UIView setAnimationDuration:0.25];
        self.view.frame = CGRectMake(0,-200,self.view.frame.size.width,self.view.frame.size.height);
        [UIView commitAnimations];
    }
}
else
{
    NSLog(@"Entered else Part");
}

Edit :- And also instead of checking (!=). you should check (==) for few UITextFields. That will be better.

Upvotes: 1

Related Questions