NSCFString EXC_BAD_ACCESS

Discussion in 'iOS Programming' started by Macman1993, Feb 27, 2011.

  1. Macman1993, Feb 27, 2011
    Last edited: Feb 27, 2011

    Macman1993 macrumors 6502

    Macman1993

    Joined:
    Nov 23, 2007
    #1
    I'm having serious problems with NSStrings, I have no idea what I'm doing wrong. Heres what I do.

    Load a NSManagedObject out of core data - Works

    Make a string object out of the key values of the NSManagedObject - Works

    Add the string object to an NSMutableArray - Works

    Pull the values out of the NSMutableArray and insert them into table view cells - Does not work, I cannot get proper values so I get an "EXC_BAD_ACCESS" error

    Code:
    //LOADING THE VALUES AND PUTTING THEM INTO THE ARRAY
    
    //NAME
    	NSString *fullName = [[object valueForKey:@"firstName"] stringByAppendingString:@" "];
    	fullName = [fullName stringByAppendingString:[object valueForKey:@"lastName"]];
    	
    	NSString *string = fullName;
    	
    	[data addObject:string];
    	[labelList addObject:@"Name:"];
    	
    	[fullName release];
    	
    	//EMAIL
    	NSString *email = [[object valueForKey:@"username"] stringByAppendingString:@
    					   "@suffieldacademy.org"];
    	
    	[data addObject:email];
    	[labelList addObject:@"Email:"];
    	
    	[email release];
    
    Code:
    //INSERTING THE VALUES OF THE ARRAY INTO THE CELLS, THIS OCCURS DURING -cellAtRowForIndexPath
    //NOTE: the textField variable is a UILabel that has been added to the cell, it works perfectly fine if I pass it a value manually (ex: textField.text = @"some string") so it is not the design of the textfield that is causing the problem
    
    int row = [indexPath row];
    NSString *value = [data objectAtIndex:row]; //CAUSES THE ERROR
    	
    	textField.text = value;
    	textField.tag = row;
    

    The proper values are inserted into the NSMutableArray but they are NSCFString objects, this happens in other instances of my code but I get no problems. The problem happens when I try to pull the values out of the NSMutableArray to use in my table view. Can someone please explain what I'm doing wrong?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Answer this for the red-hilited code: Do you own the object being released?

    If you don't know what ownership means or why it matters, then you need to review the Memory Management guide.
    http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html
     

Share This Page