178 |
178 |
179 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
179 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
180 static NSString *CellIdentifier0 = @"Cell0"; |
180 static NSString *CellIdentifier0 = @"Cell0"; |
181 static NSString *CellIdentifier1 = @"Cell1"; |
181 static NSString *CellIdentifier1 = @"Cell1"; |
182 static NSString *CellIdentifier2 = @"Cell2"; |
182 static NSString *CellIdentifier2 = @"Cell2"; |
|
183 static NSString *CellIdentifierDefault = @"CellDefault"; |
183 |
184 |
184 NSArray *hogArray; |
185 NSArray *hogArray; |
185 UITableViewCell *cell = nil; |
186 UITableViewCell *cell = nil; |
186 EditableCellView *editableCell = nil; |
187 EditableCellView *editableCell = nil; |
187 NSInteger row = [indexPath row]; |
188 NSInteger row = [indexPath row]; |
202 editableCell.textField.text = self.teamName; |
203 editableCell.textField.text = self.teamName; |
203 |
204 |
204 cell = editableCell; |
205 cell = editableCell; |
205 break; |
206 break; |
206 case 1: |
207 case 1: |
|
208 if ([indexPath row] == HW_getMaxNumberOfHogs()) |
|
209 { |
|
210 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierDefault]; |
|
211 if (cell == nil) |
|
212 { |
|
213 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
|
214 reuseIdentifier:CellIdentifierDefault] autorelease]; |
|
215 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
216 } |
|
217 |
|
218 cell.textLabel.text = NSLocalizedString(@"Select one hat for all hogs", nil); |
|
219 |
|
220 break; |
|
221 } |
|
222 |
207 editableCell = (EditableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
223 editableCell = (EditableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
208 if (editableCell == nil) { |
224 if (editableCell == nil) { |
209 editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault |
225 editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault |
210 reuseIdentifier:CellIdentifier1] autorelease]; |
226 reuseIdentifier:CellIdentifier1] autorelease]; |
211 editableCell.delegate = self; |
227 editableCell.delegate = self; |
330 default: |
346 default: |
331 DLog(@"Nope"); |
347 DLog(@"Nope"); |
332 break; |
348 break; |
333 } |
349 } |
334 } else { |
350 } else { |
335 EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath]; |
351 if (section == 1 && row == HW_getMaxNumberOfHogs()) { |
336 [cell replyKeyboard]; |
352 // 'Select one hat for all hogs' selected |
337 [aTableView deselectRowAtIndexPath:indexPath animated:NO]; |
353 [self showHogHatViewControllerForHogIndex:-1]; |
|
354 } else { |
|
355 EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath]; |
|
356 [cell replyKeyboard]; |
|
357 [aTableView deselectRowAtIndexPath:indexPath animated:NO]; |
|
358 } |
338 } |
359 } |
339 |
360 |
340 } |
361 } |
341 |
362 |
342 // action to perform when you want to change a hog hat |
363 // action to perform when you want to change a hog hat |
343 -(void) tableView:(UITableView *)aTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { |
364 -(void) tableView:(UITableView *)aTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { |
344 if (nil == hogHatViewController) |
|
345 hogHatViewController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
346 |
|
347 // cache the dictionary file of the team, so that other controllers can modify it |
|
348 hogHatViewController.teamDictionary = self.teamDictionary; |
|
349 hogHatViewController.selectedHog = [indexPath row]; |
|
350 |
|
351 // if we are editing the field undo any change before proceeding |
365 // if we are editing the field undo any change before proceeding |
352 EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath]; |
366 EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath]; |
353 [cell cancel:nil]; |
367 [cell cancel:nil]; |
354 |
368 |
|
369 [self showHogHatViewControllerForHogIndex:[indexPath row]]; |
|
370 } |
|
371 |
|
372 - (void)showHogHatViewControllerForHogIndex:(NSInteger)hogIndex |
|
373 { |
|
374 if (nil == hogHatViewController) |
|
375 hogHatViewController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
376 |
|
377 // cache the dictionary file of the team, so that other controllers can modify it |
|
378 hogHatViewController.teamDictionary = self.teamDictionary; |
|
379 hogHatViewController.selectedHog = hogIndex; |
|
380 |
355 [self.navigationController pushViewController:hogHatViewController animated:YES]; |
381 [self.navigationController pushViewController:hogHatViewController animated:YES]; |
356 } |
382 } |
357 |
|
358 |
383 |
359 #pragma mark - |
384 #pragma mark - |
360 #pragma mark Memory management |
385 #pragma mark Memory management |
361 -(void) didReceiveMemoryWarning { |
386 -(void) didReceiveMemoryWarning { |
362 [super didReceiveMemoryWarning]; |
387 [super didReceiveMemoryWarning]; |