For your second question:
tableView.style = UITableViewStyleGrouped;
Or, if you're creating it programmatically:
tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
For your first question, I assume you are setting up your cells something like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
...
setupCell(cell,indexPath.row);
return cell;
}
Where setupCell is something that checks the index and sets the cell accordingly. The IndexPath, however, tells you which row in which section to set up.
I also assume that you're returning the full number of rows in the function
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Where you should only be returning 1, since you want exactly 1 row in each section.
Then when setting up your cell, you'd want to check the indexPath.section
instead of the indexPath.row
. Rows are zero-based by section, so the calls to cellForRowAtIndexPath
will have index paths that look like this:
Section Row
0, 0
1, 0
2, 0
Whereas originally, when you had only one section, it would have been:
0, 0
0, 1
0, 2
And what you're seeing right now, since you return the same number of rows as sections is:
0, 0
0, 1
0, 2
1, 0
1, 1
1, 2
2, 0
2, 1
2, 2