Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  2. return [[self.cards valueForKeyPath:@"cards"] count];
  3. }
  4.  
  5.  
  6. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  7. [ccTableView setBackgroundColor:[UIColor clearColor]];
  8. cardsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cardsCell"];
  9.  
  10. if(cell == nil){
  11. NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"cardsCell" owner:self options:nil];
  12. cell = [topLevelObjects objectAtIndex:0];
  13. }
  14.  
  15. NSString *nmCard = [[self.cards valueForKeyPath:@"cards.name"] objectAtIndex:indexPath.row];
  16. cell.descCardLabel.text = nmCard;
  17.  
  18. return cell;
  19. }
  20.  
  21. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  22.  
  23. static NSString *CELL_ID2 = @"SOME_STUPID_ID2";
  24. // even rows will be invisible
  25. if (indexPath.row % 2 == 1)
  26. {
  27. UITableViewCell * cell2 = [tableView dequeueReusableCellWithIdentifier:CELL_ID2];
  28.  
  29. if (cell2 == nil)
  30. {
  31. cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
  32. reuseIdentifier:CELL_ID2];
  33. [cell2.contentView setAlpha:0];
  34. [cell2 setUserInteractionEnabled:NO]; // prevent selection and other stuff
  35. }
  36. return cell2;
  37. }
  38.  
  39. [ccTableView setBackgroundColor:[UIColor clearColor]];
  40. cardsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cardsCell"];
  41.  
  42. if(cell == nil){
  43. NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"cardsCell" owner:self options:nil];
  44. cell = [topLevelObjects objectAtIndex:0];
  45. }
  46.  
  47. // Use indexPath.row/2 instead of indexPath.row for the visible section to get the correct datasource index (number of rows is increased to add the invisible rows)
  48. NSString *nmCard = [[self.cards valueForKeyPath:@"cards.name"] objectAtIndex:(indexPath.row/2)];
  49. cell.descCardLabel.text = nmCard;
  50.  
  51. return cell;
  52. }
  53.  
  54.  
  55.  
  56. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  57.  
  58. // two times minus one (invisible at even rows => visibleCount == invisibleCount+1)
  59. return [[self.cards valueForKeyPath:@"cards"] count] * 2 - 1;
  60. }
  61.  
  62. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  63. {
  64. if (indexPath.row % 2 == 1)
  65. return 40;
  66. return 162;
  67. }
  68.  
  69. - (void)setFrame:(CGRect)frame {
  70. frame.origin.y += 4;
  71. frame.size.height -= 2 * 4;
  72. [super setFrame:frame];
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement