I want a sectioned UITableView but I don't know how, my situation:
I have 2 arrays
array Date ("12/08/13", "13/08/13", "17/08/13") array Count("2", "1", "5")
The count means how many rows are there in the section.
I have
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [dateArray objectAtIndex:section];
}
But how can make in the first section, 2 rows in the second section 1 row and in the third section 5 rows.
I hope someone can help me. If you have questions just ask.
Thanks.
EDIT: I get my information from my website so the array changes everyday.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// length of your section count array:
return [sectionCountArray count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// the section count from your array, converted to an integer:
return [sectionCountArray[section] integerValue];
}
UPDATE: From your comment is seems that you have a "flat" data source array.
Since the row numbers start with zero in each section, you have to compute the
index into the array from the row number and the section count of all previous sections
in cellForRowAtIndexPath
:
NSInteger flatIndex = indexPath.row;
for (NSInteger sec = 0; sec < indexPath.section; sec++)
flatIndex += [tableView numberOfRowsInSection:sec];
cell.textLabel.text = yourFlatDataArray[flatIndex]; // (Just an example!)