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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:34:51+00:00 2026-05-23T10:34:51+00:00

The basic structure of my program has the user select an item from a

  • 0

The basic structure of my program has the user select an item from a UITableView, which corresponds to a stored text file. The file is then read into an array and a dictionary, where the array has the keys (I know I can just get the keys from the dictionary itself, this isn’t my question).

The view is then changed to a UISplitView where the master view has the keys, and the detail view has the items in the dictionary attributed to that key. In this case, it’s a series of “Yes/No” questions that the user selects the answer to.

My problem is this: When I click on a cell in the UITableView (first screen), it works fine, the data is read in perfectly, and so on. When I go back to the UITableView and click on the same cell again, the program crashes. Here is the read-in-from-file method:

-(NSArray *)readFromFile:(NSString *)filePath{
    //  NSLog(@"Path was: %@", filePath);
    NSString *file = [[NSString alloc] initWithContentsOfFile:filePath];

    //  NSLog(@"File was: %@", file);
    NSScanner *fileScanner = [[NSScanner alloc] initWithString:file];

    NSString *held;
    NSString *key;
    NSMutableArray *detailStrings;
    NSMutableArray *keys = [[NSMutableArray alloc] init];
    NSMutableDictionary *details = [[NSMutableDictionary alloc] init];
    /**
    This is where the fun stuff happens!
    **/
    while(![fileScanner isAtEnd]){
        //Scan the string into held
        [fileScanner scanUpToString:@"\r" intoString:&held];
        NSLog(@"Inside the while loop");
        // If it is a character, it's one of the Key points, so we do the management necessary
        if ([[NSCharacterSet lowercaseLetterCharacterSet] characterIsMember:[[held lowercaseString] characterAtIndex: 0]]){
            NSArray *checkers = [[NSArray alloc] initWithArray:[held componentsSeparatedByString:@"\t"]];
            NSLog(@"Word at index 2: %@", [checkers objectAtIndex:2]);

            if(detailStrings != nil){
                 [details setObject:detailStrings forKey:key];
                 [detailStrings release];
            }
            NSLog(@"After if statement");
            key = [checkers objectAtIndex:2];
            [keys addObject:(NSString *) key];
            detailStrings = [[NSMutableArray alloc] init];
        }
        else if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember:[[held lowercaseString] characterAtIndex: 0]]){

            NSArray *checkers = [[NSArray alloc] initWithArray:[held componentsSeparatedByString:@"\t"]];
            NSLog(@"Word at index 1: %@", [checkers objectAtIndex:1]);
            [detailStrings addObject:[checkers objectAtIndex:1]];
        }
     }
     NSLog(@"File has been read in");
     [details setObject:detailStrings forKey:key];
     NSArray *contents = [[NSArray alloc] initWithObjects:(NSMutableArray *) keys, (NSMutableDictionary *) details, nil];

     [detailStrings release];
     return contents;
}

I’ve determined that the program crashes inside the

if(detailStrings != nil)

statement. I figure this is because I’m missing some memory management that I am supposed to be doing, but don’t have the knowledge of where it’s going wrong. Any ideas as to the problem, or why it is crashing without giving me a log?

  • 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-23T10:34:52+00:00Added an answer on May 23, 2026 at 10:34 am

    detailStrings is not initialized when you enter the while loop. When you declare NSMutableArray *detailStrings; inside a method, detailStrings is not automatically set to nil. So when you do

    if ( detailStrings != nil ) { .. }
    

    it enters the if statement and since it is not initialized, it will crash when you access detailStrings.

    Another thing is that detailStrings won’t be initialized if it enters the else part of the loop first. That will cause a crash too. So based on your requirement, either do

    NSMutableArray *detailStrings = nil;
    

    or initialize it before you enter the while loop.

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

Sidebar

Related Questions

I currently have a program which has the following basic structure main function --
I recently learned about the basic structure of the .docx file (it's a specially
My basic program structure is this: class B1 { vector <someStruct> aStruct; //some struct
This project is a basic ATM program. I'm using a file to store all
I am packaging up an rpm file which has a %postinstall section that detects
I have the current basic structure for each domain object that I need to
My view is that unless you need to change the basic structure of the
Given a pretty basic source tree structure like the following: trunk ------- QA |--------
One of the basic data structures in Python is the dictionary, which allows one
Basic requests are: human readable / text format (for easy version control) online (for

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.