iOS Dev – Assignment #1 – Extra Task #2

Visualize the currently active operation by letting the button be pushed until the second operand is entered.

A button can be displayed as pushed by “highlighting”. However, when the resultButtonPressed: method fires, the button is already highlighted and will be dehighlighted shortly after. Thus it is necessary to “wait a little bit” actually till the “normal button functionality” has finished before highlighting the button. This can be achieved by adding an operation on the main queue.
To remove the highlighting, add a property to hold the currently pressed button.

@property (nonatomic, strong) UIButton *currentButton;

- (IBAction)operationButtonPressed:(UIButton *)sender {
	...
	else
	{
		...
		self.currentButton.highlighted = NO;
	}
	...
	[[NSOperationQueue mainQueue] addOperationWithBlock:^{
		sender.highlighted = YES;
		self.currentButton = sender;
	}];
}

- (IBAction)resultButtonPressed:(id)sender {
	...
	self.currentButton.highlighted = NO;
}

- (IBAction)clearDisplay:(id)sender {
	...
	self.currentButton.highlighted = NO;
}
Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

Leave a Reply

Your email address will not be published. Required fields are marked *