My UITableViewCells take up the full viewing area. I’d like to use a grouped table so the cells appear to have rounded corners. Right now, if I set the number of sections to something greater than one, I get the number of sections in grouped style but all the cells repeat in each section. How do I setup the table so each cell is in a section?
Also, is it possible to programmatically set the table style to grouped?
For your second question:
Or, if you’re creating it programmatically:
For your first question, I assume you are setting up your cells something like this:
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
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.sectioninstead of theindexPath.row. Rows are zero-based by section, so the calls tocellForRowAtIndexPathwill 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