Skip to content

Instantly share code, notes, and snippets.

@rhysforyou
Created December 13, 2011 04:00
Show Gist options
  • Select an option

  • Save rhysforyou/1470501 to your computer and use it in GitHub Desktop.

Select an option

Save rhysforyou/1470501 to your computer and use it in GitHub Desktop.
#import <UIKit/UIKit.h>
@class Task;
@interface TaskDurationViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
@property (strong, nonatomic) Task *task;
@property (strong, nonatomic) IBOutlet UILabel *pomodoroLabel;
@property (strong, nonatomic) IBOutlet UILabel *minuteLabel;
@property (strong, nonatomic) IBOutlet UIPickerView *durationPicker;
@end
#import "TaskDurationViewController.h"
#import "Task.h"
@implementation TaskDurationViewController
@synthesize task = _task;
@synthesize pomodoroLabel = _pomodoroLabel;
@synthesize minuteLabel = _minuteLabel;
@synthesize durationPicker = _durationPicker;
#pragma mark - View lifecycle
- (void)loadView
{
[super loadView];
[self.durationPicker selectRow:((int)self.task.duration - 1) inComponent:0 animated:NO];
self.pomodoroLabel.text = self.task.durationString;
self.minuteLabel.text = self.task.minutesString;
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
# pragma mark - Picker data source
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 99;
}
# pragma mark - Picker delegate
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (row == 0) {
return @"1 Pomodoro";
} else {
return [NSString stringWithFormat:@"%d Pomodoros", row + 1];
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
[self.task setValue:[NSNumber numberWithInt:1] forKey:@"duration"];
self.pomodoroLabel.text = self.task.durationString;
self.minuteLabel.text = @"Foo";
NSLog(@"Row selected:%d, Duration: %@", row, self.task.duration);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment