TableView with grouped style - Not using interface builder
Does anyone have an example showing how to create a grouped table using code not using interface builder. I need to build a view that has different settings that are grouped into their own area. Just like if on the iPhone simulator you goto settings > safari.
Does anyone know how to do this?
I have been playing around with it but cannot seem to get the results I want, and cannot find substantial documentation explaining how it all works.
Sorry but that's not good advice - the part about storing all rows for multiple sections into a single array. That may work for a static table but it will be a nightmare if the data can change. One possible approach is to keep an array of arrays or a dictionary of arrays. Again, this is one possibility. Each array would correspond to one section. When you get the indexPath you grab the appropriate array using indexPath.section. From that array you get the correct element using indexPath.row.
Using this approach makes your data source much easier because now the method for the number of sections just calls the 'count' property on the top level array. The method for the number of rows in a section returns the 'count' of the second level array.
Don't hardcode such things. It will just make your app more prone to bugs as the data changes.
Plus I added the 3 methods mentioned above that are supposed to help create the sections. But all i get on screen is a regular table view i think. Basically the screen just has about 10 rows on it. I am not sure what I am doing wrong but if someone could explain or has an example of making a grouped table view could you please help me out.
Have you looked at the supplied example code? There are several table based example apps that come with the SDK that show how to create and use table views. Most do not use IB for the table views.
I have looked at these examples. I am a little lost with them. This is why I was hoping someone on here could actually explain how they work. The sample code is good, but some explanations would help a lot.
Have you read the "Table View Programming Guide for iPhone OS". This does a good job of putting it all together. Combined with the example code, this is how most of us learned.
The problem with these methods is, that I have to know which array (which section) is affected.
How can I handle this?
Why isn't there just one more argument with the section?
The one parameter has everything you need. Have you looked at the docs for NSIndexPath (UITableView extensions)? It has two properties: row and section.