Search code examples
objective-cuitableviewnsindexpath

indexPath.row for whole tableview, not only section?


I have a tableView wich displays content from an array with objects. But the tableview have sections for each date, and I get the same content in all the sections. I guess NSDictionary *object = [array objectAtIndex:indexPath.row]; returns the row for the section and not for the total array. How can I get the row count for the whole tableView? Or is it some other way to do it?


Solution

  • int rowsOffset = 0;
    for (int section; section ++; section < indexPath.section) {
      rowsOffset += [[[titles objectAtIndex:section] objectForKey:@"Values"] count];
    }
    
    NSDictionary *object = [array objectAtIndex:indexPath.row+rowOffset];
    

    probably better:

    NSArray *theArray = [[titles objectAtIndex:indexPath.section] objectForKey:@"Values"];
    NSDictionary *object = [theArray objectAtIndex:indexPath.row];