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 9100665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:55:27+00:00 2026-06-17T00:55:27+00:00

I have a table view in which I’m using sectionIndexTitlesForTableView to display an index.

  • 0

I have a table view in which I’m using sectionIndexTitlesForTableView to display an index. I have to display a list of universities located in different countries. Each Country can have more than one university so the table displays like this:

 1. Ecuador
    1. Universidad Catolica del Ecuador
 2. El Salvador
    1. Universidad Don Bosco
 3. Estonia
    4. Tallin University
    4. Tartu Health Care College
    4. University of Tartu
 4. Finland
    5. Aalto University

....

What I intend to do is, using the scroll search at the side, when the user touches “A” it will take you to the first entry with the letter A. For example, when I press “E” it should take me to the section “Ecuador” (displayed on the “image” above).

The problem came at the start because I had multiple sections, when I pressed “B” it would take me to “Australia”, the second section (the first being Argentina) instead of taking me to “Belgium” which would be the first Country with the B letter. I managed a workaround of this but it’s giving me errors. Here’s the code:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
   return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
}


- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    NSArray* bu =[self SectionsASaltar];
    int ins =[[bu objectAtIndex:index] intValue];

    return [[UILocalizedIndexedCollation currentCollation] sectionForSectionIndexTitleAtIndex:ins];

}


-(NSArray*)SectionsASaltar
{
    NSArray* ALF= [[NSArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z", nil];


    NSMutableArray* jumps =[[NSMutableArray alloc]initWithObjects:@"0", nil];

    int i=0; //contador de elementos
    int j=0; //contador del alfabeto

    [titl addObject:[self.secc objectAtIndex:i]];
    do {

        if ([[self.secc objectAtIndex:i] hasPrefix:[ALF objectAtIndex:j]]) {
            i++;
        }else{
            [jumps addObject:[NSString stringWithFormat:@"%d",i]];
            i++;
            j++;

        }

    } while (i<[self.secc count]);

    [jumps addObject:[NSString stringWithFormat:@"0"]];
    NSLog(@"%@",jumps);
    return jumps;
}

Where self.secc is my array with the sections and jumps is an array with the number of elements I have to skip on the index to get to next letter.

The idea of the code above is to count how many elements have the letter A, store that and skip them when the users press B, so it will go directly to the first letter B. It works fine for most of the letters but once I press around the letter M it gives me the following error:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (29) beyond bounds (28)'
*** First throw call stack:
(0x25f9012 0x21c6e7e 0x25f8deb 0x25ed7e0 0x13137be 0x1dcd2 0x10d27ee 0x21da705 0x102e920 0x102e8b8 0x10ef671 0x10efbcf 0x124396d 0x12439a6 0x10ee7e2 0x105e16d 0x105e552 0x103c3aa 0x102dcf8 0x32b3df9 0x32b3ad0 0x256ebf5 0x256e962 0x259fbb6 0x259ef44 0x259ee1b 0x32b27e3 0x32b2668 0x102b65c 0x2bbd 0x2af5 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb)

The thing I really don´t know where I’m going beyond bounds, I think it is in the line :

return [[UILocalizedIndexedCollation currentCollation]
sectionForSectionIndexTitleAtIndex:ins];

but I don´t know how that statement works so I don´t know how to fix it. Any ideas?
Also, is this the best approach for my indexing or is there an easier way to manage same-lettered sections. I know I can make another view, then have the first view have only countries ordered by letters and in a second view the universities, but I’m trying to avoid that.

  • 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-17T00:55:28+00:00Added an answer on June 17, 2026 at 12:55 am

    Your code assumes there is an entry for every letter in the alphabet. If not, then it will increment both i and J, skipping the active entry. So if you have an array that starts with the letters a, c, d, e then your code will test a with a, then c with b, incrementing both indexers and in the next loop it will test the d with c instead of c with c. Because you keep incrementing j you can go past your index of items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Grouped Table View in which I want to display Contact details. But
I have table view which is showing list of files to download. When I
I have a Table View which displays images using lazy loading from AFNetworking with
I have a custom cell for my table view which I have designed using
I have a simple table view which I have built using an example from
i have a table view in which each cell has a TextField where the
I have a Dynamic table view which has 5 prototype cells, inside each cell
I have a table view in which each cell I have added a object.
I have a table view which I'm using for some settings in my app.
Using storyboards I have a table view controller with a list of rows. When

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.