Repository navigation
Expand file tree
/
Copy pathNIAddDateViewController.m
More file actions
95 lines (66 loc) · 2.85 KB
/
Copy pathNIAddDateViewController.m
File metadata and controls
95 lines (66 loc) · 2.85 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
//
// NIAddDateViewController.m
// NoteIt
//
// Created by icelorc on 2010/12/19.
// Copyright 2010 Polydice Inc. All rights reserved.
//
#import "NIAddDateViewController.h"
@implementation NIAddDateViewController
@synthesize dataArray, dataDictionary;
- (void) viewDidLoad{
[super viewDidLoad];
[self.monthView selectDate:[NSDate date]];
}
- (NSArray*) calendarMonthView:(TKCalendarMonthView*)monthView marksFromDate:(NSDate*)startDate toDate:(NSDate*)lastDate{
[self generateRandomDataForStartDate:startDate endDate:lastDate];
return dataArray;
}
- (void) calendarMonthView:(TKCalendarMonthView*)monthView didSelectDate:(NSDate*)d{
[self.tableView reloadData];
}
- (void) calendarMonthView:(TKCalendarMonthView*)mv monthDidChange:(NSDate*)d{
[super calendarMonthView:mv monthDidChange:d];
[self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *ar = [dataDictionary objectForKey:[self.monthView dateSelected]];
if(ar == nil) return 0;
return [ar count];
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
NSArray *ar = [dataDictionary objectForKey:[self.monthView dateSelected]];
cell.textLabel.text = [ar objectAtIndex:indexPath.row];
return cell;
}
- (void) generateRandomDataForStartDate:(NSDate*)start endDate:(NSDate*)end{
// this function sets up dataArray & dataDictionary
// dataArray: has boolean markers for each day to pass to the calendar view (via the delegate function)
// dataDictionary: has items that are associated with date keys (for tableview)
NSLog(@"Delegate Range: %@ %@ %d",start,end,[start daysBetweenDate:end]);
self.dataArray = [NSMutableArray array];
self.dataDictionary = [NSMutableDictionary dictionary];
NSDate *d = start;
while(YES){
int r = arc4random();
if(r % 3==1){
[self.dataDictionary setObject:[NSArray arrayWithObjects:@"Item one",@"Item two",nil] forKey:d];
[self.dataArray addObject:[NSNumber numberWithBool:YES]];
}else if(r%4==1){
[self.dataDictionary setObject:[NSArray arrayWithObjects:@"Item one",nil] forKey:d];
[self.dataArray addObject:[NSNumber numberWithBool:YES]];
}else
[self.dataArray addObject:[NSNumber numberWithBool:NO]];
TKDateInformation info = [d dateInformationWithTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
info.day++;
d = [NSDate dateFromDateInformation:info timeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
if([d compare:end]==NSOrderedDescending) break;
}
}
@end