Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textFieldDidBeginEditing: for more than one textfield

I am fairly new to iphone programming and here I am facing some issues. Now in my application, I have two textfields and I want to fire an event while second textfield starts editing. now I am using following function

- (void)textFieldDidBeginEditing:(UITextField *)textField

but the thing is the event is being fired when the first textfield starts editing. It does not wait for the second text field. Is there any way I can use this function for the second textfield or may be somehow could know and pass it the value of the active textfield?

I tried writing the name of the textfield instead of (UITextField *)textField in the function but still the same result.

like image 919
Vik Avatar asked Apr 15 '11 23:04

Vik


1 Answers

That delegate method is gonna get called everytime the editing of ANY text field is started, so it should be you who controls what is done when this happens. I suggest you to do something like:

   -(void)textFieldDidBeginEditing: (UITextField *)textField
   {     
        if (textField == mySecondTextField)
        {
            //Do what you need
        }
        else
        {
            //Do nothing
        }
   }

I hope it helps you!

like image 106
Fran Sevillano Avatar answered Oct 07 '22 13:10

Fran Sevillano