Reputation: 315
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... :-)
Upvotes: 0
Views: 1229
Reputation: 1642
It doesn't have absolute cursor but you can try utilizing UILocalizedIndexedCollation class which is used to ease the "sectioning" of your data and proving the tableView delegate functions the required data such as the index titles, etc
Here's apple documentation link for it: https://developer.apple.com/library/ios/#documentation/iPhone/Reference/UILocalizedIndexedCollation_Class/UILocalizedIndexedCollation.html#//apple_ref/occ/cl/UILocalizedIndexedCollation
Upvotes: 0
Reputation: 18741
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
Upvotes: 0
Reputation: 1485
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...
Upvotes: 1