Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Macman1993

macrumors 6502
Original poster
Nov 23, 2007
337
16
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?
 
Last edited:
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:"];
	
	[COLOR="Red"][fullName release];[/COLOR]
	
	//EMAIL
	NSString *email = [[object valueForKey:@"username"] stringByAppendingString:@
					   "@suffieldacademy.org"];
	
	[data addObject:email];
	[labelList addObject:@"Email:"];
	
	[COLOR="Red"][email release];[/COLOR]
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.