forked from danielctull/DataCenter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCTDatePickerViewController.m
114 lines (89 loc) · 2.68 KB
/
DCTDatePickerViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// DCTDatePickerViewController.m
// Climb Tracker
//
// Created by Mike Abdullah on 08/12/2011.
// Copyright (c) 2011 Karelia Software. All rights reserved.
//
#import "DCTDatePickerViewController.h"
@implementation DCTDatePickerViewController
- (NSDate *)date;
{
return [datePicker date];
}
- (void)setDate:(NSDate *)date
{
[self view]; // make sure it's loaded
[datePicker setDate:date];
}
#pragma mark Lifecycle
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)dealloc
{
[_formatter release];
[super dealloc];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (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);
}
- (void)viewWillAppear:(BOOL)animated
{
[self dateChanged:nil]; // make sure table & picker are up-to-date
}
#pragma mark - Table View Data Source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *fallsCellIdentifier = @"Cell";
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:fallsCellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:fallsCellIdentifier] autorelease];
}
cell.textLabel.text = NSLocalizedString(@"Date", "cell title");
if (!_formatter)
{
_formatter = [[NSDateFormatter alloc] init];
_formatter.dateStyle = NSDateFormatterLongStyle;
_formatter.timeStyle = NSDateFormatterShortStyle;
}
cell.detailTextLabel.text = [_formatter stringFromDate:self.date];
return cell;
}
#pragma mark - Picker
- (void)dateChanged:(id)sender
{
[tableView reloadData];
[tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}
@end