-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathLAUpcomingEventsTableViewController.m
99 lines (66 loc) · 2.27 KB
/
LAUpcomingEventsTableViewController.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
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Adam Ziolkowski <[email protected]> and Leon Handreke <[email protected]>
* wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy us a beer in return.
* ----------------------------------------------------------------------------
*/
#import "LAUpcomingEventsTableViewController.h"
@implementation LAUpcomingEventsTableViewController
@synthesize baseDate;
@synthesize eventsNow;
@synthesize eventsSoon;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Always use an up-to-date date
baseDate = [NSDate date];
// I know caching it here is evil but I have deadlines :)
eventsNow = [[LAEventDatabase sharedEventDatabase] eventsWhile: baseDate];
eventsSoon = [[LAEventDatabase sharedEventDatabase] eventsInTimeInterval: 3600 afterDate: baseDate];
if ([eventsNow count] == 0 && [eventsSoon count] == 0){
// FOSDEM has not started
}
[[self tableView] reloadData];
}
- (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)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// One "Now", one next hour
return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return [eventsNow count];
}
else {
return [eventsSoon count];
}
}
- (LAEvent *)eventForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
return [eventsNow objectAtIndex: indexPath.row];
}
else {
return [eventsSoon objectAtIndex: indexPath.row];
}
}
- (NSString *)tableView: (UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0) {
return @"Now";
}
else {
return @"Next hour";
}
}
@end