Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling two UITextFields and delegates

Tags:

objective-c

Hi I was taking care of one UITextField easily. e.g., Set delegate of UITextField my view controller and implement such method:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{

    // Removes the keyboard from the screen
    [self.textFieldProperty1 resignFirstResponder];


    return YES;
}

But what if I have two UITextFields? A delegate for both of them will still be my view controller. And how do I implement the above method then? Like this?

 - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {

        // Removes the keyboard from the screen
        [self.textFieldProperty1 resignFirstResponder];
        [self.textFieldProperty2 resignFirstResponder];


        return YES;
    }
like image 995
user2054339 Avatar asked Nov 18 '25 18:11

user2054339


1 Answers

change your method as you pass the delegate to your property it will automatically identify from which textField method is called:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{

    // Removes the keyboard from the screen
    [textField resignFirstResponder];


    return YES;
}
like image 50
KDeogharkar Avatar answered Nov 21 '25 09:11

KDeogharkar