Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 30th, 2012  |  syntax: None  |  size: 1.68 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Placeholder cell in a UITableView
  2. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  3. {
  4.     if(section == 1)
  5.     {
  6.         return @"Section One";
  7.     }
  8.     if(section == 0)
  9.     {
  10.         return @"Section Two";
  11.     }
  12.     return @"";
  13. }
  14.  
  15. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  16. {
  17.     if (section == 1)
  18.     {
  19.         return self.sectionOne.count;
  20.     }
  21.     else
  22.     {
  23.         return self.sectionTwo.count;
  24.     }
  25. }
  26.  
  27. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  28. {
  29.  
  30.     NSArray *theSource =[[NSArray alloc] init];
  31.  
  32.     if(indexPath.section == 1)
  33.     {
  34.         theSource = self.sectionOne;
  35.     }
  36.     else
  37.     {
  38.         theSource = self.sectionTwo;
  39.     }
  40.  
  41.     // See if there's an existing cell we can reuse
  42.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
  43. if (cell == nil)
  44.     {
  45.         // No cell to reuse => create a new one
  46.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"];
  47.         cell.backgroundView = [[UIImageView alloc] init];
  48.         // Continue creating cell
  49.         }
  50.   }
  51.        
  52. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  53. {
  54.     if (datasource == empty)
  55.         return 1;
  56.     else
  57.         return [datasource count];
  58. }
  59.        
  60. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  61. {
  62.     if (datasource == empty)
  63.          return stub cell;
  64.     else
  65.          return regular cell;
  66. }
  67.        
  68. sectionTitleArray = [@"First Section", @"Second Section", @"Third Section"]