---
title: "One Array - Multiple sections – NSIndexPath"  
description: "One Array - Multiple sections – NSIndexPath"  
author: "Tarun Kumar"  
published: 2015-07-27  
updated: 2015-07-27  
canonical: https://www.mindstick.com/forum/23378/one-array-multiple-sections-nsindexpath  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# One Array - Multiple sections – NSIndexPath

I have one big [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) with many values. I've sorted out the sections but I can't seem to get the indexpath right.

Basically, what I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to do, is that if the [previous](https://yourviews.mindstick.com/view/81421/unlock-2-0-is-just-like-previous-corona-lockdowns) [section](https://yourviews.mindstick.com/view/297/reservation-for-economically-weaker-section) has 50 rows, the next indexpath.row should be 51->. The one after that should be 60-> and so fourth.

```
NSLog(@"current indexpath.row: %ld",(long)indexPath.row);
NSLog(@"current section: %ld",(long)indexPath.section);
for (int i = indexPath.section; i == indexPath.section; i++) {
            NSLog(@"number of rows: %ld",(long)[self tableView:tableView                                                             numberOfRowsInSection: indexPath.section]);
            NSLog(@"in section: %ld",(long)indexPath.section);
     if (i++) {
        // add previous number of rows plus current
        int previousRows = [self tableView:tableView numberOfRowsInSection:                                                                                          indexPath.section*2];
        NSLog(@"now indexpath: %ld",(long)previousRows+indexPath.row);    }
}
```

I hope I've made my [question](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time) clear [enough](https://answers.mindstick.com/qa/48601/who-is-the-writer-of-the-one-life-is-not-enough) for you to understand.

## Replies

### Reply by Anonymous User

NSIndexPath doesn't work this way. NSIndexPath starts from 0 for every section.

If I understand correctly, you want to know the global index value to access the array. For that case, I have been using this little method:

```
- (int)getGlobalRowFor:(int)row at:(int)section {
    if(section == 0) {
        return row;
    } else {
        int count = 0;
        for(int i = 0; i < section; i++) {
            // This is where you put your own numbers for section counts.
            // This is my model, yours could be different.
            count += [[[self.sections objectAtIndex:i] objectForKey:@"sectionCount"]                                                                                                               intValue];        }        return count + row;
    }
}
```


---

Original Source: https://www.mindstick.com/forum/23378/one-array-multiple-sections-nsindexpath

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
