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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:55:28+00:00 2026-05-23T11:55:28+00:00

I have a issue with this peice of code, I am trying to save

  • 0

I have a issue with this peice of code, I am trying to save some data to a plist for later use, and if the user reopens the view, it should have the current segment selected for each segment control on my view.

however when I try and save the information, it crashes on the line

[array addObject:gender];

please help 🙂 it gives EXC_BAD_ACCESS

-(IBAction)genderSelection:(id)sender
{
    if([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
    {
        gender = @"Male";
        //NSLog(gender);
    }
    else {
        gender = @"Female";
        //NSLog(gender);
    }

}

-(IBAction)contactTypeSelection:(id)sender
{
    if([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
    {
        contactType = @"a";
        //NSLog(gender);
    }
    else {
        contactType = @"b";
        //NSLog(gender);
    }

}

-(IBAction)saveData:(id)sender
{
    NSMutableArray *array = [[NSMutableArray alloc] init];

    [array removeAllObjects];

    [array addObject:field1.text];
    [array addObject:field2.text];
    [array addObject:gender];
    [array addObject:contactType];

    [array writeToFile:[self dataFilePath] atomically:YES];
    [array release];
}

-(NSString *)dataFilePath
{
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [path objectAtIndex:0];

    return [documentsDirectory stringByAppendingPathComponent:kFilename];
}

-(void)viewWillAppear:(BOOL)animated
{

    NSString *filePath = [self dataFilePath];

    if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
    {
        NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];

        field1.text = [array objectAtIndex:0];
        field2.text = [array objectAtIndex:1];

        gender = [array objectAtIndex:2];
        contactType = [array objectAtIndex:3];

        if([gender isEqualToString:@"Male"])
        {
            genderSegment.selectedSegmentIndex = 0;
        }
        else
        {
            genderSegment.selectedSegmentIndex = 1;
        }

        if([contactType isEqualToString:@"a"])
        {

        }
        else
        {

        }


        [array release];
    }
}

-(IBAction)textDone:(id)sender
{
    [sender resignFirstResponder];
}



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [gender release]; //need to release
    [contactType release]; //need to release
    [field1 release]; //need to release
    [field2 release]; //need to release
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    gender = @"Male";
    contactType = @"a";
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    gender = nil; //need to release
    contactType = nil; //need to release
    field1 = nil ; //need to release
    field2 = nil; //need to release
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
  • 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-23T11:55:29+00:00Added an answer on May 23, 2026 at 11:55 am

    You didn’t didn’t initialize your gender property. You need:

    - (void)viewDidLoad
    {
    
        [super viewDidLoad];
    
        self.gender=[[NSString alloc]init];
    
        self.gender = @"Male";
    
    //so something here
    
        // Do any additional setup after loading the view from its nib.
    
    }
    

    NOTE: If you use the @synthesize compiler directive then you need to the self-dot notation everywhere to refer to the property e.g. self.gender.

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

Sidebar

Related Questions

Ok so I've spent a couple hours trying to resolve this issue and have
I have this weird issue. I am trying to create a service that synchs
I have an issue with an Actionscript 2 piece of code. I'm trying to
I have this code I am trying out and I can't figure out how
I have been trying to wrap my head around this issue but I am
I have this issue with ComboBox that uses IEnumerable<Brush> as ItemsSource; the problem lies
I do not currently have this issue , but you never know, and thought
Continuing my problem from yesterday, the Silverlight datagrid I have from this issue is
I am having trouble with the following SQL statement. I have had this issue
I have this strange issue with my web app. You see, I'm using jQuery

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.