Quote:
Originally Posted by raheel
Hi guys,
I've got a situation, where i have to add sections to a tableview.
An NSMutableArray is having objects with anNSInteger Type and NSString title.
Code:
ExOb *eob = (ExOb *)[appDelegate.ExArray objectAtIndex:indexPath.row];
want i want to do is,
if (eob.Type == 1){
//add to indexpath.section 1
} else if (eob.Type == 2){
//add to section 2
}
else if (eob.Type == 1){
//add to section 3
}
however, i can actually implement this cuz i simply dont kno how to.
and also, to return the exact number of rows where eob.type==1.. etc
Most examples have arrays for each sections.
any suggestions would be great
|
I had done something similar before and a quick test shows that it should work for you.
In the :
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
you need to create a new index like this:
Code:
int matchingIndex = ((indexPath.section *2)+ indexPath.row);
This tracks with a group of 2 rows per section. If your sections have a different number of rows then adjust the multiplier for that.
Of course if your sections have varying row counts the math doesn't work. It worked for me.
Deanne