문제

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];
}
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top