-
Notifications
You must be signed in to change notification settings - Fork 3
/
DetailsViewController.m
91 lines (69 loc) · 1.64 KB
/
DetailsViewController.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
#import "DetailsViewController.h"
@implementation DetailsViewController
- (id)init:(User *)user {
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
self.user = user;
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
if (section == 3) {
NSArray *phones = self.user.contact.phones;
if ([phones count] == 0) {
return 1;
}
return [phones count];
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"Cell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:identifier];
}
NSString *text = @"";
if (indexPath.section == 0) {
text = [NSString stringWithFormat:@"%@ %@", self.user.name,
self.user.lastName];
}
else if (indexPath.section == 1) {
text = self.user.contact.emailAddress;
}
else if (indexPath.section == 2) {
text = self.user.contact.birthday;
}
else {
NSArray *phones = self.user.contact.phones;
if ([phones count] > 0) {
text = [phones objectAtIndex:indexPath.row];
}
}
[cell.textLabel setText:text];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section {
if (section == 0) {
return @"Name";
}
else if (section == 1) {
return @"Email";
}
else if (section == 2) {
return @"Birthday";
}
else {
return @"Phones";
}
}
@end