1

I want to use the values entered in the text Fields by the users in two columns and perform the necessary operations to generate the desired output and display the result as an alert message in XCODE? Is there any way that i can perform the calculations using the text fields ?

got the ans:

-(IBAction)buttonPressed1:(id)sender
{
    // You may also need to check if your string data is a valid number
    int result = [Number1.text intValue] + [Number2.text intValue];
    SumAnswer.text = [NSString stringWithFormat:@"%d", result];
}
4

1 回答 1

1

上面这段代码是正确的。这将在第三个文本框中显示结果。如果你想显示结果UIAlertView

试试 UIAlertView

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result !!" message:[NSString stringWithFormat:@"%d", result]; delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    // optional - add more buttons:
    [alert addButtonWithTitle:@"Yes"];
    [alert show];

并且不要忘记添加UIAlertViewDelegate.h 类

于 2013-02-15T08:00:03.197 回答