33 } |
33 } |
34 |
34 |
35 // load the list of teams in the teams directory |
35 // load the list of teams in the teams directory |
36 -(void) viewWillAppear:(BOOL)animated { |
36 -(void) viewWillAppear:(BOOL)animated { |
37 [super viewWillAppear:animated]; |
37 [super viewWillAppear:animated]; |
38 |
38 |
39 NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
39 NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
40 NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES]; |
40 NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES]; |
41 self.listOfTeams = array; |
41 self.listOfTeams = array; |
42 [array release]; |
42 [array release]; |
43 |
43 |
44 [self.tableView reloadData]; |
44 [self.tableView reloadData]; |
45 } |
45 } |
46 |
46 |
47 // modifies the navigation bar to add the "Add" and "Done" buttons |
47 // modifies the navigation bar to add the "Add" and "Done" buttons |
48 -(void) toggleEdit:(id) sender { |
48 -(void) toggleEdit:(id) sender { |
49 BOOL isEditing = self.tableView.editing; |
49 BOOL isEditing = self.tableView.editing; |
50 [self.tableView setEditing:!isEditing animated:YES]; |
50 [self.tableView setEditing:!isEditing animated:YES]; |
51 |
51 |
52 if (isEditing) { |
52 if (isEditing) { |
53 [self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Edit",@"from the team panel")]; |
53 [self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Edit",@"from the team panel")]; |
54 [self.navigationItem.rightBarButtonItem setStyle: UIBarButtonItemStyleBordered]; |
54 [self.navigationItem.rightBarButtonItem setStyle: UIBarButtonItemStyleBordered]; |
55 self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem; |
55 self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem; |
56 } else { |
56 } else { |
66 } |
66 } |
67 |
67 |
68 // add a team file with default values and updates the table |
68 // add a team file with default values and updates the table |
69 -(void) addTeam:(id) sender { |
69 -(void) addTeam:(id) sender { |
70 NSString *fileName = [[NSString alloc] initWithFormat:@"Default Team %u.plist", [self.listOfTeams count]]; |
70 NSString *fileName = [[NSString alloc] initWithFormat:@"Default Team %u.plist", [self.listOfTeams count]]; |
71 |
71 |
72 createTeamNamed([fileName stringByDeletingPathExtension]); |
72 createTeamNamed([fileName stringByDeletingPathExtension]); |
73 |
73 |
74 [self.listOfTeams addObject:fileName]; |
74 [self.listOfTeams addObject:fileName]; |
75 [fileName release]; |
75 [fileName release]; |
76 |
76 |
77 // order the array alphabetically, so teams will keep their position |
77 // order the array alphabetically, so teams will keep their position |
78 [self.listOfTeams sortUsingSelector:@selector(compare:)]; |
78 [self.listOfTeams sortUsingSelector:@selector(compare:)]; |
79 |
79 |
80 [self.tableView reloadData]; |
80 [self.tableView reloadData]; |
81 } |
81 } |
82 |
82 |
83 #pragma mark - |
83 #pragma mark - |
84 #pragma mark Table view data source |
84 #pragma mark Table view data source |
91 } |
91 } |
92 |
92 |
93 // Customize the appearance of table view cells. |
93 // Customize the appearance of table view cells. |
94 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
94 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
95 static NSString *CellIdentifier = @"Cell"; |
95 static NSString *CellIdentifier = @"Cell"; |
96 |
96 |
97 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
97 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
98 if (cell == nil) { |
98 if (cell == nil) { |
99 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
99 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
100 } |
100 } |
101 |
101 |
102 NSUInteger row = [indexPath row]; |
102 NSUInteger row = [indexPath row]; |
103 NSString *rowString = [[self.listOfTeams objectAtIndex:row] stringByDeletingPathExtension]; |
103 NSString *rowString = [[self.listOfTeams objectAtIndex:row] stringByDeletingPathExtension]; |
104 cell.textLabel.text = rowString; |
104 cell.textLabel.text = rowString; |
105 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
105 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
106 |
106 |
107 return cell; |
107 return cell; |
108 } |
108 } |
109 |
109 |
110 // delete the row and the file |
110 // delete the row and the file |
111 -(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
111 -(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
112 NSUInteger row = [indexPath row]; |
112 NSUInteger row = [indexPath row]; |
113 |
113 |
114 NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@",TEAMS_DIRECTORY(),[self.listOfTeams objectAtIndex:row]]; |
114 NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@",TEAMS_DIRECTORY(),[self.listOfTeams objectAtIndex:row]]; |
115 [[NSFileManager defaultManager] removeItemAtPath:teamFile error:NULL]; |
115 [[NSFileManager defaultManager] removeItemAtPath:teamFile error:NULL]; |
116 [teamFile release]; |
116 [teamFile release]; |
117 |
117 |
118 [self.listOfTeams removeObjectAtIndex:row]; |
118 [self.listOfTeams removeObjectAtIndex:row]; |
119 [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; |
119 [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; |
120 } |
120 } |
121 |
121 |
122 |
122 |
124 #pragma mark Table view delegate |
124 #pragma mark Table view delegate |
125 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
125 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
126 if (childController == nil) { |
126 if (childController == nil) { |
127 childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
127 childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
128 } |
128 } |
129 |
129 |
130 NSInteger row = [indexPath row]; |
130 NSInteger row = [indexPath row]; |
131 NSString *selectedTeamFile = [listOfTeams objectAtIndex:row]; |
131 NSString *selectedTeamFile = [listOfTeams objectAtIndex:row]; |
132 |
132 |
133 // this must be set so childController can load the correct plist |
133 // this must be set so childController can load the correct plist |
134 childController.teamName = [selectedTeamFile stringByDeletingPathExtension]; |
134 childController.teamName = [selectedTeamFile stringByDeletingPathExtension]; |
135 [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
135 [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
136 |
136 |
137 [self.navigationController pushViewController:childController animated:YES]; |
137 [self.navigationController pushViewController:childController animated:YES]; |