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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:20:15+00:00 2026-05-30T19:20:15+00:00

After cleaning up my code and making it ready for deployment I encountered a

  • 0

After cleaning up my code and making it ready for deployment I encountered a weird problem. When I try to add a contact to my tableview it always crashes when the empty is array. After that its not problem to add as many as you want. And also when I delete a contact and the array is empty, it also crashes with the same error message:

Terminating app due to uncaught exception ‘NSRangeException’, reason:
‘ -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array’

Here is what I do: I add a contact via php to my database, read it out with xml and give it back to the app so the user can instantly see what happened (adding a contact that is). There is a lot of code involved so I stick to the basics for now.
When the view loads the array gets allocated. User can add a contact. While adding the contact a php file is called that creates the xml file where the contacts are saved.

Here is where I get the object back and paste it into my array and display it

self.filteredListContent = [NSMutableArray arrayWithCapacity:[self.tabelle count]];

self.tableView.scrollEnabled = YES;

numbers = [[NSMutableArray alloc] init];

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
NSString *fileName = [prefs stringForKey:@"number"];
NSString *cc = [prefs stringForKey:@"Code"];
NSString *urlString = [NSString stringWithFormat: @"http://myserver/%@%@.xml", cc, fileName];
NSURL *url = [NSURL URLWithString: urlString];

DataFileToObjectParser *myParser = [[DataFileToObjectParser alloc] parseXMLAtUrl:url toObject:@"contacts" parseError:nil];

for(int i = 0; i < [[myParser items] count]; i++) {
    contacts *new = [[Telefonbuch alloc] init];
    new = (contacts *) [[myParser items] objectAtIndex:i];
    [numbers addObject:new];
    [self.tableView reloadData];

And here is how it gets displayed, nothing special:

NSString *TableText = [[NSString alloc] initWithFormat:@"%@", [[numbers objectAtIndex:indexPath.row] fname]]; 
NSString *TableText2 = [[NSString alloc] initWithFormat:@"%@", [[numbers objectAtIndex:indexPath.row] lname]];    
NSString *cellValue = [NSString stringWithFormat:@"%@ %@", TableText, TableText2];
cell.textLabel.text = cellValue;
  • 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-30T19:20:17+00:00Added an answer on May 30, 2026 at 7:20 pm

    Your loop sounds strange.

    for(int i = 0; i < [[myParser items] count]; i++) {
        contacts *new = [[Telefonbuch alloc] init];
        new = (contacts *) [[myParser items] objectAtIndex:i];
        [numbers addObject:new];
        [self.tableView reloadData];
    

    First avoid to use new keyword (as user1118321 already suggested).

    Then, what is contacts? Is contacts a superclass of type Telefonbuch?

    What do these two lines mean?

    contacts *new = [[Telefonbuch alloc] init];
    new = (contacts *) [[myParser items] objectAtIndex:i];
    

    You alloc-init an instance of Telefonbuch class to a new (avoid this) variable but then you assign that variable to another object. Why?

    The right code could be like the following.

    for(int i = 0; i < [[myParser items] count]; i++) {
       Telefonbuch* newContact = (Telefonbuch*) [[myParser items] objectAtIndex:i]; // or contacts* newContact = (contacts*) [[myParser items] objectAtIndex:i];
       // maybe it could be better to rename contacts with a capital letter
       [numbers addObject:newContact];
    }
    
    [self.tableView reloadData];
    

    Some notes

    If you want to add or delete item to a table view, you need to do it in 2 stages:

    1) Deal with your model

    [yourModel removeObjectAtIndex:row];
    

    2) Deal with your table’s animation

    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    

    If you need to download content, maybe you could consider to do it asynchrously without blocking the main thread. In particular, this is could be the synchronous call that could be a blocking one (since I don’t have any details I’m only supposing it).

    DataFileToObjectParser *myParser = [[DataFileToObjectParser alloc] parseXMLAtUrl:url toObject:@"contacts" parseError:nil];
    

    If you don’t use ARC, pay attention to memory management.

    Hope it helps.

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

Sidebar

Related Questions

Every time I pull code into my repository after making changes to JS or
After consecutive builds of a solution without making any changes to an assembly's code
EDIT: Problem solved! After cleaning and rebooting it just disappeared! I don't know what
After cleaning a folder full of HTML files with TIDY, how can the tables
I have been given the unenviable task of cleaning up after a developer who
The Story After cleaning up my Dreamhost shared server's home folder from all the
Why doesn't the code below clear all array list data? Console.WriteLine(Before cleaning: + Convert.ToString(ID.Count));
I have an application that I've been tasked with cleaning up after. The application
I have problem running and debugging this piece of code: bool readSectionHeaders(char* path, int
Help please, After numerous hours searching for the solution to my problem i have

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.