views:

221

answers:

2

I thought that would be very common and easy iPhone App. In the main app I connect to database, retrieve values from database (NSDate converted to NSString)n and put into single array. Then in one of the views I populate UITableView with elements from the array. UITableView is grouped (sections). I step through array to discover number of sections (change section if new day). How do I retrieve correct element of array in cellForRowAtIndexPath? IndexPath.section and IndexPath.row seem useless as row starts count from zero for each section. If number of rows in each section was the same it would have been easy:

[arryData objectAtIndex:(indexPath.row)+indexPath.section*[tblMatchesView numberOfRowsInSection:indexPath.section]];

But number of rows in each section varies... :-)

A: 

Separate your data into arrays of arrays (based on the number of different days) once you get it from the database, that'd be the simplest solution...

ivans
Thanks Ivans. I was trying to avoid it. I can't be believe iPhone SDK doesn't have absolute cursor (it knows number of sections and rows already populated...).
Biko
A: 

How about storing different date sections in different arrays? For example, you can have an array A of array. You can loop through the original arrays yourself, if you found a new day, you just create a new array and put it into the array A. And then, when you loop over the cell, you can get the section number to get the correct array and based on the row number to get the correct elemenet in the array

vodkhang
Thanks. That was Ivans suggestion too (arrays of arrays). I thought I just missed something in docs but looks like it's missing absolute cursor. Oh well,... thanks anyway.
Biko