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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:51:39+00:00 2026-06-12T15:51:39+00:00

I am trying to count my array to set as the number of rows

  • 0

I am trying to count my array to set as the number of rows in my table and then multiply it by 2 because I have an invisible cell in between each cell to make the cells look separated. Every time I try to build, I get this error:

Terminating app due to uncaught exception ‘NSRangeException’, reason:
‘* -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]’

This is the code I am using:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  return [xmlParser.calls count] * 2; 
}

cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
  static NSString *CellIdentifier = @"Cell";
  static NSString *CELL_ID2 = @"SOME_STUPID_ID2";
  JointCAD *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row];
  self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"texture3.png"]];

  [self.tableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"texture3.png"]]];

  if (indexPath.row % 2 == 1) {
    UITableViewCell * cell2 = [tableView dequeueReusableCellWithIdentifier:CELL_ID2];

    if (cell2 == nil) {
      cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:CELL_ID2];
      [cell2.contentView setAlpha:0];
      [cell2 setUserInteractionEnabled:NO];
      [cell2 setBackgroundColor:[UIColor clearColor]];
    }
    return cell2;
  }

  TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

  if (cell == nil) {
    cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  }

  cell.callTypeLabel.text = currentCall.currentCallType;
  cell.locationLabel.text = currentCall.location;
  cell.unitsLabel.text = currentCall.units;
  cell.stationLabel.text = [@"Station: " stringByAppendingString:currentCall.station];
  cell.contentView.layer.backgroundColor = [UIColor whiteColor].CGColor;
  cell.contentView.layer.frame = CGRectMake(0, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height);
  cell.contentView.layer.borderWidth = 1.0;
  cell.contentView.layer.borderColor = [UIColor blackColor].CGColor;

  if ([currentCall.county isEqualToString:@"W"]) {  
    cell.countyImageView.image = [UIImage imageNamed:@"blue.png"];
  } else {
    cell.countyImageView.image = [UIImage imageNamed:@"green.png"];
  }

  if ([currentCall.callType isEqualToString:@"F"]) {  
    cell.callTypeImageView.image = [UIImage imageNamed:@"red.png"];
  } else {
    cell.callTypeImageView.image = [UIImage imageNamed:@"yellow.png"];
  }
  return cell;
}
  • 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-12T15:51:41+00:00Added an answer on June 12, 2026 at 3:51 pm

    EDIT:

    Made a closer look. Just add the /2:

    JointCAD *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row / 2];
    

    And it’s going to work.
    Just noticed the same answer below from richard.


    As mayuur noticed:

    in - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section:

    // n = [xmlParser.calls count]
    // Ok, we have n*2 items (but calls has only n!):
    return [xmlParser.calls count] * 2;
    // calls has n items in it, but you return n*2 items
    

    And then in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath:

    // n = [xmlParser.calls count]
    // give me object from calls at index (which will be in range [0; n*2 - 1], 
    // which could be beyond [0; n-1] which you originally have)
    JointCAD *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row];
    

    So you should remove multiply by 2 or suggest something by your own, you’ll always going to get this error unless xmlParser.calls is an empty array.

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

Sidebar

Related Questions

I am trying to count the number of occurrences in an array of cart
I'm trying to count the number of records that have a null DateTime value.
Trying to set an array and a count, which are both static members, by
Trying to count how many elements within the array are not equal to 0,
I'm trying to count all the values inside an array, I've tried using count()
I am trying to count the number of times a user has clicked on
I am trying to count the occurrences of certain dates in my MySQL table
I'm trying to count the number of times that -- occurs in a string.
I am just trying to count the number of white spaces to the LEFT
I'm trying to count the occurrences of a distinct set of cities and countries

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.