Question

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];
}
Was it helpful?

Solution

This above code is correct. This will show result in third textbox. If you want to show result in UIAlertView

Try 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];

And don't forget to add UIAlertViewDelegate in .h class

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top