0

I want UITableView to show cells in section separated (have distance, blank space, between them).

So I've come up with this:

InventoryViewController.m

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[[InventoryStore sharedInventory] allInventories] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Inventory *p = [[[InventoryStore sharedInventory] allInventories]
                  objectAtIndex:[indexPath section]];

    StepperCell *cell = [tableView
                         dequeueReusableCellWithIdentifier:@"StepperCell"];

    [cell setController:self];
    [cell setTableView:tableView];

    [[cell nameLabel] setText:[p inventoryName]];
    [[cell valueLabel] setText:
     [NSString stringWithFormat:@"$%d", [p value]]];
    [[cell quantityLabel] setText:
     [NSString stringWithFormat:@"%d", [p quantity]]];
    cell.stepper.value = [p quantity];

    return cell;
}

and of course in AppDelegate.m

InventoryViewController *inventoryViewController = [[InventoryViewController alloc] initWithStyle:UITableViewStyleGrouped];

My question is, is there a better or simpler way to separate cells, but in the same section? I want to have one section, and draw data from one array, but these cells should have distance between each other.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
1337code
  • 169
  • 1
  • 3
  • 11
  • You could try this: http://stackoverflow.com/questions/4804632/uitableview-separator-line or this: http://stackoverflow.com/questions/3521310/how-to-increase-the-uitableview-seperator-height – brainray Sep 30 '12 at 11:56

1 Answers1

0

If the table has blank separators (i.e. separatorStyle set to UITableViewCellSeparatorStyleNone) then you can inject blank cells between each cell.

e.g.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 if (indexPath.row % 2) {
 /* Your cell rendering code goes here */
 }
 else {
  UITableViewCell * blankCell = ....;
 }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return (numberOfInventoryItems * 2) - 1;
}
lorean
  • 2,150
  • 19
  • 25