Search code examples
ios6uitextfieldxcode4.5ibaction

Summing two elements of two UITextFields


I'm having an issue with summing the element of one UITextField with the element of another UITextField and having the answer displayed in a third UITextField (called answer). The summation would happen by pressing a button. Here's the code I have for the IBAction:

-(IBAction) {

 answer.text = [[NSString stringWithFormat:@"%i",([text1.text intValue] + [text2.text intValue])]];

}

All I get is an error message saying "Expected Identifier"


Solution

  • Your message needs a name, and you have too many brackets. Try this:

    -(IBAction)myAction {
      answer.text = [NSString stringWithFormat:@"%i",([text1.text intValue] + [text2.text intValue])];
    }