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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:38:45+00:00 2026-05-25T00:38:45+00:00

I have a pickerView, it appears in the Simulator but as soon as I

  • 0

I have a pickerView, it appears in the Simulator but as soon as I try and scroll it, it crashes EXC_BAD_ACCESS in the main.m file.

I know it is to do with the arrays that I load in from a pList because when I try this with arrays that are initialised in the program it works (see commented out sections), is this something to do with ‘nil’ at the end of the array? If so how can I see this and how can I add it.

I appreciate any help on this please I’m pulling what’s left of my hair out, and I’m fairly new to this…

// Method to define the numberOfComponent in a picker view.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}


// Method to define the numberOfRows in a component using the array.

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent :(NSInteger)component 
{ 
if (component==0)
{
    return [maximumSpeed count];
}
else
{
    return[warningTime count];
}

}

//PickerViewController.m
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{

    NSString *stringToReturn = nil;

    switch (component) 
    {
        case 0:
            stringToReturn = [maximumSpeed objectAtIndex:row];
            break;
        case 1:
            stringToReturn = [warningTime objectAtIndex:row];
            break;
    }
return stringToReturn;
}




// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];

// finding the path and loading the pList as a dictionary into 'data'
NSString *pListFile = [[NSBundle mainBundle] pathForResource:@"PropertyList" ofType:@"plist"];
data =[NSDictionary dictionaryWithContentsOfFile:pListFile];

// get and set up the 2 arrays
maximumSpeed = [data valueForKey:@"MaximumSpeed"]; 
warningTime = [data valueForKey:@"WarningTime"]; 


//maximumSpeed =[[NSArray alloc] initWithObjects:@"Running",@"Crying",@"Boring",@"Working",nil];
//warningTime = [[NSArray alloc] initWithObjects: @"Happy", @"Sad" , @"Good", @"joyce",nil];

NSLog(@"%@", maximumSpeed);

NSLog(@"%@", warningTime);

}

 (void)viewDidUnload
{
[self setTxt1:nil];
[pickerView release];
pickerView = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}



- (void)dealloc {
[txt1 release];
[pickerView release];
[warningTime release];
[maximumSpeed release];
[super dealloc];
}
  • 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-25T00:38:46+00:00Added an answer on May 25, 2026 at 12:38 am

    You do not own the object(s) returned by valueForKey, in this case, your arrays. These objects are getting released and you end up with a dangling pointer. Hence, the crash. The problem is here:

    maximumSpeed = [data valueForKey:@"MaximumSpeed"]; 
    warningTime = [data valueForKey:@"WarningTime"]; 
    

    You need to retain them.

    maximumSpeed = [[data valueForKey:@"MaximumSpeed"] retain]; 
    warningTime = [[data valueForKey:@"WarningTime"] retain];
    

    The following works because you own the objects you create.

    //maximumSpeed =[[NSArray alloc] initWithObjects:@"Running",@"Crying",@"Boring",@"Working",nil];
    //warningTime = [[NSArray alloc] initWithObjects: @"Happy", @"Sad" , @"Good", @"joyce",nil];
    

    This also applies to dictionaryWithContentsOfFile:

    data =[NSDictionary dictionaryWithContentsOfFile:pListFile];
    

    You can retain (like before) or switch to the alloc-init version:

    data = [[NSDictionary dictionaryWithContentsOfFile:pListFile] retain];
    // or
    data = [[NSDictionary alloc] initWithContentsOfFile:pListFile];
    

    You do not own the objects returned by methods unless the method name begins with “alloc”, “new”, “copy” or “mutableCopy”.

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

Sidebar

Related Questions

I have my pickerview set up and everything works fine, but right now I
I have one mainViewController that is also a delegate for a pickerview contained in
I have a pickerView and depending on the selection in that pickerView i want
I have added a pickerView inside a scrollview but when i change the value
I have a 2 components, dependent pickerView . I have a preview UIImageView that
I have a UIPickerView that appears in a UIPopoverController atop a graph view. When
I have a UIPickerView that appears when a textfield is selected: -(void) showPicker {
I have an app that I am currently making that has a PickerView and
I have a picker view that has a list of numbers to pick from.
I have pickerView with two rows and I need to save position of both

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.