public
Description: an iPhone application for Remember the Milk.
Homepage: http://deadbeaf.org/out/milpon/
Clone URL: git://github.com/mootoh/milpon.git
milpon / ui / DueDateSelectController.m
100644 140 lines (116 sloc) 3.91 kb
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// TrialDueDateSelectController.m
// Milpon
//
// Created by mootoh on 1/26/09.
// Copyright 2009 deadbeaf.org. All rights reserved.
//
 
#import "DueDateSelectController.h"
#import "UICCalendarPicker.h"
 
@implementation DueDateSelectController
 
enum {
   ROW_TODAY = 0,
   ROW_TOMORROW = 1,
   ROW_CALENDAR = 2
};
 
@synthesize parent;
 
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
       calendar_picker = [[UICCalendarPicker alloc] initWithSize:UICCalendarPickerSizeExtraLarge];
       calendar_picker.delegate = self;
       self.title = @"Due Date";
    }
    return self;
}
 
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
 
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
 
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
 
#pragma mark Table view methods
 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
   return 1;
}
 
 
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return 3;
}
 
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   
   static NSString *CellIdentifier = @"TrialDueDateSelect";
   
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
   }
   
   switch (indexPath.row) {
      case ROW_TODAY:
         cell.text = @"Today";
         break;
      case ROW_TOMORROW:
         cell.text = @"Tomorrow";
         break;
      case ROW_CALENDAR:
         [calendar_picker showInView:cell.contentView animated:NO];
         //[cell.contentView addSubview:calendar_picker];
         break;
      default:
         break;
   }
   return cell;
}
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   switch (indexPath.row) {
      case ROW_TODAY:
         [self.parent setDue:[NSDate date]];
         break;
      case ROW_TOMORROW: {
         NSDate *now = [NSDate date];
         NSDateComponents *comps = [[NSDateComponents alloc] init];
         [comps setDay:1];
         NSDate *date = [[NSCalendar currentCalendar] dateByAddingComponents:comps toDate:now options:0];
         [comps release];
         [self.parent setDue:date];
         break;
      }
      case ROW_CALENDAR:
         [tableView deselectRowAtIndexPath:indexPath animated:NO];
         return;
      default:
         break;
   }
         
   [self.navigationController popViewControllerAnimated:YES];
   [self.parent updateView]; // TODO: should reload due row only.
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   return (indexPath.row == 2) ? 340.0f : 44.0f;
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
 
- (void)dealloc
{
    [super dealloc];
}
 
- (void) picker:(UICCalendarPicker *)picker didSelectDate:(NSArray *)selectedDate
{
   if (selectedDate == nil) return;
   [self.parent setDue:[selectedDate objectAtIndex:0]];
   [self.navigationController popViewControllerAnimated:YES];
   [self.parent updateView]; // TODO: should reload due row only.
}
 
@end