76 |
76 |
77 |
77 |
78 #pragma mark - |
78 #pragma mark - |
79 #pragma mark Table view data source |
79 #pragma mark Table view data source |
80 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
80 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
81 return 2; |
81 return 1; |
82 } |
82 } |
83 |
83 |
84 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
84 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
85 NSInteger rows; |
85 return [self.hatArray count]; |
86 if (0 == section) |
|
87 rows = 1; |
|
88 else |
|
89 rows = [self.hatArray count]; |
|
90 return rows; |
|
91 } |
86 } |
92 |
87 |
93 // Customize the appearance of table view cells. |
88 // Customize the appearance of table view cells. |
94 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
89 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
95 |
90 |
99 if (cell == nil) { |
94 if (cell == nil) { |
100 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
95 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
101 } |
96 } |
102 |
97 |
103 NSDictionary *hog = [[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:selectedHog]; |
98 NSDictionary *hog = [[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:selectedHog]; |
104 if (0 == [indexPath section]) { |
99 |
105 cell.textLabel.text = self.title; |
100 NSString *hat = [[hatArray objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; |
106 cell.imageView.image = nil; |
101 cell.textLabel.text = hat; |
|
102 cell.imageView.image = [hatSprites objectAtIndex:[indexPath row]]; |
|
103 |
|
104 if ([hat isEqualToString:[hog objectForKey:@"hat"]]) { |
|
105 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
106 self.lastIndexPath = indexPath; |
|
107 } else { |
107 cell.accessoryType = UITableViewCellAccessoryNone; |
108 cell.accessoryType = UITableViewCellAccessoryNone; |
108 } else { |
|
109 cell.textLabel.text = [[hatArray objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; |
|
110 if ([cell.textLabel.text isEqualToString:[hog objectForKey:@"hat"]]) { |
|
111 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
112 self.lastIndexPath = indexPath; |
|
113 } else { |
|
114 cell.accessoryType = UITableViewCellAccessoryNone; |
|
115 } |
|
116 |
|
117 cell.imageView.image = [hatSprites objectAtIndex:[indexPath row]]; |
|
118 } |
109 } |
119 |
110 |
120 return cell; |
111 return cell; |
121 } |
112 } |
122 |
113 |
123 |
114 |
124 /* |
115 /* |
162 |
153 |
163 |
154 |
164 #pragma mark - |
155 #pragma mark - |
165 #pragma mark Table view delegate |
156 #pragma mark Table view delegate |
166 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
157 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
167 if (1 == [indexPath section]) { |
158 int newRow = [indexPath row]; |
168 int newRow = [indexPath row]; |
159 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
169 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
160 |
170 |
161 if (newRow != oldRow) { |
171 if (newRow != oldRow) { |
162 // if the two selected rows differ update data on the hog dictionary and reload table content |
172 // if the two selected rows differ update data on the hog dictionary and reload table content |
163 NSDictionary *oldHog = [[teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:selectedHog]; |
173 NSDictionary *oldHog = [[teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:selectedHog]; |
164 |
174 |
165 NSMutableDictionary *newHog = [[NSMutableDictionary alloc] initWithDictionary: oldHog]; |
175 NSMutableDictionary *newHog = [[NSMutableDictionary alloc] initWithDictionary: oldHog]; |
166 [newHog setObject:[[hatArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"hat"]; |
176 [newHog setObject:[[hatArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"hat"]; |
167 [[teamDictionary objectForKey:@"hedgehogs"] replaceObjectAtIndex:selectedHog withObject:newHog]; |
177 [[teamDictionary objectForKey:@"hedgehogs"] replaceObjectAtIndex:selectedHog withObject:newHog]; |
168 [newHog release]; |
178 [newHog release]; |
169 |
179 |
170 // tell our boss to write this new stuff on disk |
180 // tell our boss to write this new stuff on disk |
171 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
181 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
172 [self.tableView reloadData]; |
182 [self.tableView reloadData]; |
173 |
183 |
174 self.lastIndexPath = indexPath; |
184 self.lastIndexPath = indexPath; |
175 [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
185 [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
176 } |
186 } |
177 [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
187 [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
178 [self.navigationController popViewControllerAnimated:YES]; |
188 [self.navigationController popViewControllerAnimated:YES]; |
|
189 } |
|
190 } |
179 } |
191 |
180 |
192 |
181 |
193 #pragma mark - |
182 #pragma mark - |
194 #pragma mark Memory management |
183 #pragma mark Memory management |