code_junkie

Last indexed cell in UITableView is taking on wrong font

Nov 12th, 2011
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2. NSInteger row = [indexPath row];
  3. NSInteger section = [indexPath section];
  4.  
  5. static NSString *CellIdentifier = @"Student";
  6.  
  7. cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
  8. if (cell == nil) {
  9. cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
  10. }
  11. // Configure the cell
  12. if([studentsSearch count] > 0) {
  13. cell.text = (NSString *)[[[studentsSearch objectAtIndex:section] objectAtIndex:row] valueForKey:@"name"];
  14. cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
  15. } else {
  16. if(isSearching == YES)
  17. cell.text = @"No students available.";
  18. else
  19. cell.text = @"No students have been added for this school.";
  20.  
  21. cell.font = [UIFont fontWithName:@"Georgia" size:14];
  22. cell.accessoryType = UITableViewCellAccessoryNone;
  23. }
  24.  
  25. return cell;
  26. }
  27.  
  28. cell.font = [UIFont systemFontOfSize: 14];
  29.  
  30. cell.text = (NSString *)[[[...
  31. cell.accessoryType = ...
  32.  
  33. - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  34. NSInteger row = [indexPath row];
  35. NSInteger section = [indexPath section];
  36.  
  37. static NSString *StudentCellIdentifier = @"Student";
  38. static NSString *NoneCellIdentifier = @"None";
  39.  
  40. // did we find students?
  41. BOOL found = [studentsSearch count] > 0;
  42.  
  43. // get/create correct cell type
  44. cell = [tv dequeueReusableCellWithIdentifier:(found ? StudentCellIdentifier : NoneCellIdentifier)];
  45. if (cell == nil) {
  46. cell = [[UITableViewCell alloc] initWithFrame:CGRectZero
  47. reuseIdentifier:(found ? StudentCellIdentifier : NoneCellIdentifier)];
  48. }
  49.  
  50. // return a student, or None cell if no studnts found
  51. if( found )
  52. {
  53. cell.text = (NSString *)[[[studentsSearch objectAtIndex:section] objectAtIndex:row] valueForKey:@"name"];
  54. cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
  55. }
  56. else
  57. {
  58. if(isSearching == YES)
  59. cell.text = @"No students available.";
  60. else
  61. cell.text = @"No students have been added for this school.";
  62. cell.font = [UIFont fontWithName:@"Georgia" size:14];
  63. cell.accessoryType = UITableViewCellAccessoryNone;
  64. }
  65.  
  66. return [cell autorelease];
  67. }
Add Comment
Please, Sign In to add comment