My app needs to record a time interval by setting a start and stop time.
I want only the start button enabled at first, with the stop button being disabled.
On clicking the start button, I want the start button disabled (the following code accomplishes this fine), but I want this click to also enable the stop button. Clicking the stop button would render the stop button disabled (again, the following code handles this part as well).
I would also like to create a reset button that would return the start and stop buttons to their initial state - that is, the start button enabled and the stop button disabled, but I am pretty sure I can figure that out on my own if I get an answer to my initial query. I'm using Xcode 5 if that matters.
Thanks in advance!
- (IBAction)startButton:(UIButton *)sender
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm:ss.SS"];
_startTimeLabel.text = [formatter stringFromDate:[NSDate date]];
UIButton *startButton = (UIButton *)sender;
startButton.enabled = NO;
}
- (IBAction)stopButton:(UIButton *)sender
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm:ss.SS"];
_stopTimeLabel.text = [formatter stringFromDate:[NSDate date]];
UIButton *stopButton = (UIButton *)sender;
stopButton.enabled = NO;
}