Reputation: 32091
I'm building a basic calculator app for iPhone. I've got all the basics in it, but I'm just tweaking it now. Currently, if I press a digit, then an operation, then another digit and hit =, then the result is displayed. What I want is when I press a digit followed by an operation, I'd like the operation to be displayed on the screen. So here's what I have:
NSString *operation=[[sender titleLabel] text];
[display setText:operation];
double result=[[self brain] performOperation:operation];
[display setText:[NSString stringWithFormat:@"%g",result]];
And so this code only displays the last line, not the operation. If I comment the last line out however, the operation does display. So I'm thinking if I can let some time pass before the 2nd setText is called, this would solve my problem-unless there is another way?
Upvotes: 1
Views: 82
Reputation: 11315
You could use performSelector:withObject:afterDelay
[self performSelector:@selector(...) withObject:nil afterDelay:1];
Upvotes: 0
Reputation: 14160
Of course, you are rewriting display with the second setText:
call.
Why not use:
[display setText:[NSString stringWithFormat:@"%@%g", operation, result]]
Upvotes: 3