/
ProjectDetailViewController.m
117 lines (90 loc) · 3.27 KB
/
ProjectDetailViewController.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
//
// ProjectDetailViewController.m
// iGitHub
//
#import "ProjectDetailViewController.h"
#import "CommitsViewController.h"
#import "Git.h"
@implementation ProjectDetailViewController
@synthesize detailItem;
- (void)viewWillAppear:(BOOL)animated {
// Update the view with current data before it is displayed
[super viewWillAppear:animated];
// Scroll the table view to the top before it appears
[self.tableView reloadData];
[self.tableView setContentOffset:CGPointZero animated:NO];
self.title = [detailItem desc];
}
// Standard table view data source and delegate methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// There are two sections, for info and stats
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger rows = 0;
switch (section) {
case 0:
// For project data, there is name
rows = 1;
break;
case 1:
// For the branches section, there is size
rows = [[detailItem branches] count];
break;
default:
break;
}
return rows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"tvc";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
//cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSString *cellText = nil;
switch (indexPath.section) {
case 0:
cellText = [detailItem desc];
break;
case 1:
cellText = [[[detailItem branches] objectAtIndex:indexPath.row] objectAtIndex:0];
break;
default:
break;
}
cell.text = cellText;
return cell;
}
/*
Provide section titles
HIG note: In this case, since the content of each section is obvious, there's probably no need to provide a title, but the code is useful for illustration.
*/
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *title = nil;
switch (section) {
case 0:
title = NSLocalizedString(@"Project Info", @"Git Project Information");
break;
case 1:
title = NSLocalizedString(@"Branches", @"Git Project Refs");
break;
default:
break;
}
return title;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
CommitsViewController *commitsViewController = [[CommitsViewController alloc] initWithStyle:UITableViewStylePlain];
NSArray *refArray = [[detailItem branches] objectAtIndex:indexPath.row];
NSLog(@"refs:%@", refArray);
commitsViewController.gitRepo = detailItem;
commitsViewController.gitRef = [refArray objectAtIndex:0];
commitsViewController.gitSha = [refArray objectAtIndex:1];
NSLog(@"TEST");
// Push the commit view controller
[[self navigationController] pushViewController:commitsViewController animated:YES];
[commitsViewController release];
}
@end