PDA

View Full Version : Filling different sections in a tableview




VeniVidiVici-NL
Jun 22, 2010, 03:12 AM
Hey guys,

I'm fairly new to programming and I ran into a problem while working on an app. I've made three sections in my table view (not alphabetic, but each section represents a subject). Now i also have 3 arrays which I want to show in the corresponding sections.
But here's my problem, how do i tell the tableview which array has to be displayed in which section?

I already have the number of rows laid out in each section.

Hope you can help me :)



robbieduncan
Jun 22, 2010, 04:16 AM
Use the well documented tableView:cellForRowAtIndexPath: (http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewDatasource_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITableViewDataSource/tableView:cellForRowAtIndexPath:) path method. Note that an index path tells you both the section and row.

VeniVidiVici-NL
Jun 22, 2010, 04:29 AM
Oke, now i've got a filled tableview. But, now all the sections use the same array. So the first sections displays the first word of my array, the second section displays the second word and so on. I want each array in a different section.

Never mind, i got it worked out. I just needed to tell that there is a row and a section and then i could use an if-statement.

Thanks for the help!

robbieduncan
Jun 22, 2010, 04:32 AM
Oke, now i've got a filled tableview. But, now all the sections use the same array. So the first sections displays the first word of my array, the second section displays the second word and so on. I want each array in a different section.

Then your code is wrong. Either post it and hope someone is kind enough to fix it for you or fix it yourself.

PhoneyDeveloper
Jun 22, 2010, 09:46 AM
The way to do this is to make a single data structure that represents the data for the table. It needs to have a structure similar to the structure of the table. I use an array of arrays of dictionaries usually.

Each dictionary represents the data for a row. The top level array represents the list of sections. The second level arrays each represent a section.

All the code for the tableview callbacks becomes very simple if you set things up like this.

goods003
Dec 21, 2010, 12:51 AM
Can you post on how you ended up solving the problem..I'm basically doing the same thing and I'm stuck with just getting the same array coming up.

Thanks,
Matt