-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEducationController.m
executable file
·178 lines (146 loc) · 6.08 KB
/
EducationController.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//
// EducationController.m
// TradeShowInfo
//
// Created by Elon on 4/14/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "EducationController.h"
#import "Constants.h"
#import "EducationDao.h"
#import "EditEducation.h"
@implementation EducationController
@synthesize educationsArray;
@synthesize educationView;
@synthesize orderBy;
@synthesize sortIndex;
- (IBAction)educationOnSort:(id) sender{
UISegmentedControl *sg = sender;
self.sortIndex = sg.selectedSegmentIndex;
[self refreshEducationView];
}
- (IBAction)addEducationClicked:(id) sender{
EditEducation *newEducation = [[EditEducation alloc] initWithNibName:@"EditEducation" bundle:nil];
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = @"Education";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
newEducation.title=@"New Education";
newEducation.edit = FALSE;
newEducation.status = 0;
[[self navigationController] pushViewController:newEducation animated:YES];
}
- (void) refreshEducationView{
self.educationsArray = [NSMutableArray array];
educationDao = [[EducationDao alloc] init];
self.educationsArray = [educationDao select:self.sortIndex];
[educationView reloadData];
}
- (void) viewWillAppear:(BOOL) animated {
[super viewWillAppear:animated];
[self refreshEducationView];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.sortIndex = 1;
self.educationView.backgroundColor = [Constants backgroundColor];
self.educationView.separatorColor = [Constants tableLineColor];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.educationsArray count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *) tableView{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"SeminarCell";
UITableViewCell *educationCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (educationCell == nil)
{
educationCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}else {
UIView *viewToRemove1 = nil;
viewToRemove1 = [educationCell.contentView viewWithTag:1];
if (viewToRemove1)
[viewToRemove1 removeFromSuperview];
UIView *viewToRemove2 = nil;
viewToRemove2 = [educationCell.contentView viewWithTag:2];
if (viewToRemove2)
[viewToRemove2 removeFromSuperview];
UIView *viewToRemove3 = nil;
viewToRemove3 = [educationCell.contentView viewWithTag:3];
if (viewToRemove3)
[viewToRemove3 removeFromSuperview];
UIView *viewToRemove4 = nil;
viewToRemove4 = [educationCell.contentView viewWithTag:4];
if (viewToRemove4)
[viewToRemove4 removeFromSuperview];
}
educationCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Education *s = [educationsArray objectAtIndex:indexPath.row];
CGRect titleFrame = CGRectMake(20.0, 2.0, 260.0, 30.0);
UILabel *titleLabel = [[[UILabel alloc] initWithFrame:titleFrame] autorelease];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textColor = [UIColor blackColor];
titleLabel.textAlignment = UITextAlignmentLeft;
titleLabel.font = [UIFont boldSystemFontOfSize:16.0];
titleLabel.tag = 1;
titleLabel.text = s.title;
[educationCell.contentView addSubview:titleLabel];
CGRect datetimeFrame = CGRectMake(20.0, 30.0, 140.0, 20.0);
UILabel *dateTimeLabel = [[[UILabel alloc] initWithFrame:datetimeFrame] autorelease];
dateTimeLabel.backgroundColor = [UIColor clearColor];
dateTimeLabel.textColor = [Constants labelTextColor];
dateTimeLabel.textAlignment = UITextAlignmentLeft;
dateTimeLabel.font = [UIFont systemFontOfSize:12.0];
dateTimeLabel.tag = 2;
dateTimeLabel.text = [self converStrToShowTimeFomart:s.time];
[educationCell.contentView addSubview:dateTimeLabel];
CGRect locationFrame = CGRectMake(20.0, 50.0, 140.0, 20.0);
UILabel *locationLabel = [[[UILabel alloc] initWithFrame:locationFrame] autorelease];
locationLabel.backgroundColor = [UIColor clearColor];
locationLabel.textColor = [Constants labelTextColor];
locationLabel.textAlignment = UITextAlignmentLeft;
locationLabel.font = [UIFont systemFontOfSize:12.0];
locationLabel.tag = 3;
locationLabel.text = [NSString stringWithFormat:@"%@%@", @"Location:", s.location];
[educationCell.contentView addSubview:locationLabel];
CGRect importanceFrame = CGRectMake(180.0, 50.0, 100.0, 20.0);
UILabel *importanceLabel = [[[UILabel alloc] initWithFrame:importanceFrame] autorelease];
importanceLabel.backgroundColor = [UIColor clearColor];
importanceLabel.textColor = [Constants labelTextColor];
importanceLabel.textAlignment = UITextAlignmentLeft;
importanceLabel.font = [UIFont systemFontOfSize:12.0];
importanceLabel.tag = 4;
importanceLabel.text = [NSString stringWithFormat:@"%@%d", @"Importance:", [s getImportance]];
[educationCell.contentView addSubview:importanceLabel];
return educationCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 72.0;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath{
Education *education = [educationsArray objectAtIndex:indexPath.row];
EditEducation *detailViewController = [[EditEducation alloc] initWithNibName:@"EditEducation" bundle:nil];
detailViewController.title = @"Your Seminars/Workshops";
detailViewController.edit = TRUE;
detailViewController.status = 1;
[detailViewController setIndex:[education getIndex]];
[self.navigationController pushViewController:detailViewController animated:YES];
}
- (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 {
[super viewDidUnload];
[educationDao release];
self.educationsArray = nil;
}
- (void)dealloc {
[super dealloc];
}
@end