Xcode iOS SDK 6.1 を使用して電卓を作成しています。しかし、私の電卓は 2 つの数値を足し合わせることができないため、問題に直面しました。電卓は常に答えとして最初の数字を教えてくれるようです。問題を解決する方法はありますか?
コードは次のとおりです。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize FirstNumber,SecondNumber;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.FirstNumber.delegate = self;
self.SecondNumber.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc
{
[FirstNumber release];
[SecondNumber release];
[super dealloc];
}
- (IBAction)Calculate:(id)sender
{
NSString *finalNumberString;
int firstNumberInt, secondNumberInt, finalNumberInt;
firstNumberInt = [FirstNumber.text integerValue];
secondNumberInt = [SecondNumber.text integerValue];
finalNumberInt = firstNumberInt + secondNumberInt;
UIAlertView *alerting = [[UIAlertView alloc]initWithTitle:@"Answer" message:[NSString stringWithFormat:@"The answer is %d",finalNumberInt] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
[alerting show];
_FinalNumber.text = [[NSString alloc] initWithFormat:@"%i",finalNumberInt];
}
- (BOOL)textFieldShouldReturn:(UITextField*)textField
{
[FirstNumber resignFirstResponder];
[SecondNumber resignFirstResponder];
return NO;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch view] == self.view)
{
[FirstNumber resignFirstResponder];
[SecondNumber resignFirstResponder];
}
}
@end