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

  • SEARCH
  • Home
  • 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 586367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:06:00+00:00 2026-05-13T15:06:00+00:00

actually I’m have a very simple problem (that’s for sure) I just can’t find

  • 0

actually I’m have a very simple problem (that’s for sure) I just can’t find the root cause.

The problem is, that after calling the numberOfSectionsInTableView Method to get the number of Sections (24 in my case) the method numberOfRowsInSection gets called but with the last section (23).

This causes an out of bound index when scrolling.

So, what happens?
I’m receiving the data of the last section (23) and even the number of rows of the last section (23) and afterwards the sections are moving forward like 0,1,2,3,etc…

An example:
I have a section with the section header “#” for special characters. In my case the last section is the “X” for all values beginning with an “X”.

When I call my App, the section title has been set correctly to “#” but the data shows all the “X” values.
At this point I have 31 “X” values. When I now scroll to the last of the 31 rows, the app crashes because of an out of index error.

I think everything would work correctly If the sections wouldn’t start with the last one and afterwards continue with the first ones (23,0,1,2,3,4,etc).
I just can’t find the place where or why the section hast the value 23 on the first place.

—EDIT 2 BEGINS:
initialising the array:

    alphabetArray = [[NSMutableArray alloc] init];

First I fill a dictionary like this (for all letters incl. special chars):

charDict = [[NSMutableDictionary alloc] init];

if ([charSpecialArray count] > 0)   {

    [charDict setObject:charSpecialArray forKey:@"Special"];
    [alphabetArray addObject:@"Special"];
}

if ([charAArray count] > 0) {

    [charDict setObject:charAArray forKey:@"A"];
    [alphabetArray addObject:@"A"];
}

—EDIT 2 ENDS

So here I’m just filling the first dictionary Object with all “#” values (going on with all the other values)

Then I call the numberOfSectionsInTableView method:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  return [charDict count];
}

here the numberOfRowsInSection goes:

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

NSString *key = [alphabetArray objectAtIndex:section];  
NSArray *array = [charDict objectForKey:key];
return [array count];
 }

}

and the cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

  static NSString *CellIdentifier = @"Cell";

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


if(cell == nil)
  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"] autorelease];

if ([charSpecialArray count] > 0)   {

    Char *charSpecial = (Char *)[[charSpecialArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

    cell.textLabel.numberOfLines = 1;
    cell.detailTextLabel.numberOfLines = 2;
    [cell.detailTextLabel setFont:[UIFont boldSystemFontOfSize: 12]];

    cell.textLabel.text = charSpecial.ta;
    cell.detailTextLabel.text = charSpecial.descriptionEN;
}

if ([charAArray count] > 0) {

    Char *charA = (Char *)[[charAArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

    cell.textLabel.numberOfLines = 1;           
            cell.detailTextLabel.numberOfLines = 2;
    [cell.detailTextLabel setFont:[UIFont boldSystemFontOfSize: 12]];

    cell.textLabel.text = charA.ta;
    cell.detailTextLabel.text = charA.descriptionEN;

    }

again for all characters…

Any suggestions how to fix that?

added
initialization code .h:

#import <UIKit/UIKit.h>

@interface Char : NSObject {
NSString *ta;
NSString *report;
NSString *descriptionDE;
NSString *descriptionEN;
}

@property (nonatomic, retain) NSString *ta;
@property (nonatomic, retain) NSString *report;
@property (nonatomic, retain) NSString *descriptionDE;
@property (nonatomic, retain) NSString *descriptionEN;


-(id)initWithTa:(NSString *)t report:(NSString *)re descriptionDE:(NSString *)dde     descriptionEN:(NSString *)den;

@end

initialization code .m:

#import "SCode.h"

@implementation Char

@synthesize ta, report, descriptionDE, descriptionEN;

-(id)initWithTa:(NSString *)t report:(NSString *)re descriptionDE:(NSString *)dde descriptionEN:(NSString *)den {
self.ta = t;
self.report = re;
self.descriptionDE = dde;
self.descriptionEN = den;
return self;
}

- (void)dealloc {

[ta release];
[report release];
[descriptionDE release];
[descriptionEN release];
[super dealloc];
}

@end
  • 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-05-13T15:06:01+00:00Added an answer on May 13, 2026 at 3:06 pm

    You’ve got a big problem with your cellForRowAtIndexPath. CharsSpecial is accessed no matter what section you are in (so long as it has one item), and it may very well not have as many items as that section. This is most likely causing the crash. If your code is well written, then an out of order table shouldn’t crash anything.

    IndexPath has two components, section and row. In order to get the data you want out of a 2D array, you should use [[topArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]. Likewise, numberOfRows should use [[topArray objectAtIndex:indexPath.section] count] and numberOfSections should use [topArray count]. This way, all of these methods are consistent. You will need to adapt this for dictionaries, but that should be trivial.

    Once you’ve done that and you can scroll the table, post a new question about the order of your data, and include all the code that modifies listOfItems.

    Edit:

    ListOfItems seems to only hold the one dictionary, which means you don’t really need it. I recommended using an array instead of a dictionary as your top level container because it will make numberOfRows simpler, but to use it, you need to replace, not encapsulate, the dictionary.

    If you want to continue using the dictionary as the top level container that’s OK. You should change numberOfSections to count the number of items in the dictionary rather than the listOfItems array. NumberOfRows should look something like this:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        NSString *key = [sectionNameArray objectAtIndex:section];  
        NSArray *array = [dictionary objectForKey:key];
        return [array count];
    }
    

    Where sectionNameArray is an array of strings you use for dictionary keys (they don’t have to be the actual section names).

    Edit 2:

    A few things:

    1) alphabetArray has a memory leak, you shouldn’t retain it as it’s already been retained by alloc.

    2) Any sections that you want to skip need to be removed from the alphabetArray. For this reason it might be better to start with an empty array and add a letter when you get to that if statement (if([charAArray count] >0) for example).

    3) In cellForRow, you seem to be trying to display one item from each letter array all together in each table cell. Is this your intention? The reason you are only seeing the last value is because you keep changing the text of your label (if charAArray has any objects, it overwrites the value charSpecicalArray set). I suspect that what you really want to do is use the code I posted above to select one array, then use the indexPath row to select one item from that array, and set the labels using that one item. Is this correct?

    Edit 3:

    cellForRowAtIndexPath is supposed to return one cell given an indexPath, not all the cells for the table. I don’t think you are modifying your letter arrays (you shouldn’t be), so what you want is something like this:

    NSString *key = [alphabetArray objectAtIndex:section];  
    NSArray *array = [charDict objectForKey:key];
    Char *myChar = (Char *)[array objectAtIndex:indexPath.row];
    
    cell.textLabel.numberOfLines = 1;
    cell.detailTextLabel.numberOfLines = 2;
    [cell.detailTextLabel setFont:[UIFont boldSystemFontOfSize: 12]];
    
    cell.textLabel.text = myChar.ta;
    cell.detailTextLabel.text = myChar.descriptionEN;
    

    This should replace all of the if([array count] >0) sections in cellForRowAtIndexPath

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

Sidebar

Related Questions

Actually not sure on the terminology of what I'm trying to do. I have
Actually i have millions of records of people in my server database and i
Actually i'm working in a project which need print a test page to a
Actually haven't found the answer for this one. What for and why do i
Actually, my question was asked a year ago in this topic - Why do
Actually I'm always using Generic Collections and I frequently use List<>. Some scenarios I
Actually what I am looking for loading is loading the page first and then
actually i want to know the info of any folder or file through ant
Actually, the subject is a question. I want to draw on top of the
Actually, my sub-menu is on display : none . I need to display the

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.