Search code examples
objective-cuitextfielduilabelibaction

Change label text based on textfield


I'm making a little demo app and I'm having trouble changing. Heres the thing: I have a UIButton that every click will add a character in a NSString in a UITextField. And I put an IBAction(Mudar_Resposta) on that UITextField(campo) in the part 'Value Changed'. In that IBAction, I put that:

- (IBAction)MudarResposta:(id)sender {
   campo.text=@"lol";
}

But I can't get it to work. Any ideas?

Thanks.


Solution

  • The proper way to get it to work is to connect an action method to the Touch Up Inside event for your button. Within that method, edit they text for your text field.

    - (IBAction)mudarResponsta:(id)sender {    // Connect to Touch Up Inside of your button
        campo.text = [NSString stringWithFormat:%@ %@", campo.text, @"lol"];    // Add string ' lol' every time it's called
    }
    

    Connecting to Value Changed will never invoke the method because the value is never being changed—you're connecting the changing method to the change…if that makes any sense.