Handling Multiple Text Fields and EditingDidEnd

Discussion in 'iOS Programming' started by justfred, Oct 6, 2009.

  1. justfred macrumors newbie

    May 8, 2009
    If I have multiple UITextFields and use Interface Builder to call an IBAction update() for Editing Did End, is there an easy way to determine what text field was just edited from within update()?

    Other creative ways I'm considering:
    subclass UITextField
    create a unique IBAction for each text field
    override textViewShouldEndEditing

    but which is best? or is there a magic convenience method I missed?
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Is your update defined like so?:
    - (IBAction)update:(id)sender;
    If so, the sender parameter will contain the UITextField that triggered the action, and you can use that in your logic, normally along the lines of this:
    - (IBAction)update:(id)sender {
        UITextField *theTextField = (UITextField *)sender;
        if (theTextField == textField1) {
            // do stuff for the first text field here
  3. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    You can set the tag in the textField to the row or some other value and then check that with the sender in your action. Also if you subclass UITableViewCell you can make the cell the delegate and have the cell call back to your view controller and then pass back whatever info you like. You can easily add the row or indexPath to this callback if you want.

Share This Page