Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:26:47+00:00 2026-06-13T23:26:47+00:00

Okay I am trying to create an indexPath value from a NSArray of NSDictionary

  • 0

Okay I am trying to create an indexPath value from a NSArray of NSDictionary values so that when I go through to my tableview I can place an accessory tick on the side.

I have an NSArray of NSDictionaries that look like this

{
        HAS = 1;
        ISL = 1;
        ISV = 0;
        MAN = BANKING;
        MON = 324;
}

So the array would about 80 of these entries each with different values..

To create the IndexPath I would need to count the number of unique first letters of MAN until MAN == selected String This would give me the Section number.

Then I would need to count how many entries are in the selected section type for rows.

I have had some help already from here but I failed to identify a flaw in my logic.. for the row I was counting all of the entires instead of from the start of the selected section which ment my row count was totally stuffed. Below is a example of what I am trying to achieve.

a, aa, b, c, d, dd, ddd, dddd, e, f, g, gg

the user selects ddd so the indexpath would be

section

a, b, c, (d), e, f, g = 3

row

d, dd, (ddd), dddd = 2

I can get the section fine like so

NSArray *MANArray = [sortedArray valueForKey:@"MAN"];

NSMutableArray *letters = [NSMutableArray array];
NSString *currentLetter = nil;
for (NSString *string in MANArray) {
    if (string.length > 0) {
        NSString *letter = [string substringToIndex:1];
        if (![letter isEqualToString:currentLetter]) {
            [letters addObject:letter];
            currentLetter = letter;
        }
    }
}
NSArray *firstLetterArray = [NSArray arrayWithArray:letters];
int sectionCount = 0;
for(int i=0; i<[firstLetterArray count]; i++){
    if( [[firstLetterArray objectAtIndex:i] isEqualToString:completedStringLetter]){
        sectionCount = i;
        NSLog(@"%d", sectionCount);
    }
}

But I am just stuck when trying to get the row count from the selected section.

any help would be HUGELY appreciated.

UPDATE:

This is what I have done to count until the selected value but like I said its incorrect as it needs to start from the section depending on the first letter.

NSNumber * myNumber = [NSNumber numberWithInteger:[modIdString integerValue]];

//                
NSArray *subarray = [sortedArray valueForKey:@"MOD"];
for(int i=0; i<[subarray count]; i++){
   if( [[subarray objectAtIndex:i] isEqualToNumber:myNumber]){
      //you have found it, do whatever you need, and break from the loop
      modelResultIndexPath = nil;
      modelResultIndexPath = [NSIndexPath indexPathForRow:sectionCount inSection:i];
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:26:48+00:00Added an answer on June 13, 2026 at 11:26 pm

    How about converting the array with values "a, aa, b, c, d, dd, ddd, dddd, e, f, g, gg" to an NSDictionary of arrays as,

    dict = {
            a = [a, aa];
            b = [b];
            c = [c];
            d = [d, dd, ddd, dddd];
            e = [e];
            f = [f];
            g = [g, gg];
    }
    

    and then [[dict allKeys] count] should give you the section count and [[dict valueForKey:@"d"] count] should give the corresponding row count.

    In order to convert the array to array of dictionaries, Use this code,

    NSArray *sortedArray = [arrayData sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
    NSMutableDictionary *arraysByLetterDict = [NSMutableDictionary dictionary];
    
    for (NSString *value in sortedArray) {
        NSString *firstLetter = [value substringWithRange:NSMakeRange(0, 1)];
        NSMutableArray *arrayForLetter = [arraysByLetterDict objectForKey:firstLetter];
        if (!arrayForLetter) {
            arrayForLetter = [NSMutableArray array];
            [arraysByLetterDict setObject:arrayForLetter forKey:firstLetter];
        }
        [arrayForLetter addObject:value];
    }
    NSLog(@"Dictionary: %@", arraysByLetterDict);
    

    Indexpath can be calculated as,

    NSArray *allKeys = [[dict allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
    int totalSectionCount = [allKeys count];
    int totalRowCount = [[dict valueForKey:@"d"] count];
    
    int sectionCount = [allKeys indexOfObject:@"d"];
    int rowCount = [[dict valueForKey:@"d"] indexOfObject:@"ddd"];
    
    modelResultIndexPath = [NSIndexPath indexPathForRow:rowCount inSection:sectionCount];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create ONE javascript function that can do the following: onclick, a
I'm trying to create a custom deployer in Tridion 2011 SP1 that can index
Okay, I'm trying to create a simple app that will draw a shape (I'm
Okay, I seem to be having a problem. I'm trying to create a twicker
Okay so I'm trying to make a little gag program that will run away
Okay here is what I'm trying to do: I have a model object that
I am trying create a small web application that allows a user to login
Okay, I am trying to create a webpage where it uploads a photo to
Okay, so I'm trying to create a Call class on top of my Controller,
Okay. So I am currently trying to create a list of an interface in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.