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

collinssol

macrumors newbie
Original poster
Oct 15, 2009
15
0
I have a chunk of code that goes out and gets back a csv string from a rest service i coded. I split that into an array and i want to populate a uipickerview with the array but when my code gets to the count array rows part that when it bails out with EXE_BAD_ACCESS. I will past in the code below and would appreciate any insight on where to start fixing this.

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	arrayActions = [[NSMutableArray alloc] init];
	ivTechAppDelegate *mainDelegate = (ivTechAppDelegate *)[[UIApplication sharedApplication] delegate];
	NSURL *url = [NSURL URLWithString:@"http://mysite.com/iv_server.php"];
	ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
	request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
	[request setPostValue:@"1" forKey:@"sw"];
	[request setPostValue:mainDelegate.user_name forKey:@"usern"];
	[request startSynchronous];
	NSString *resp = [request responseString];
	arrayActions = [resp componentsSeparatedByString:@","];
	
	NSLog(@"array: %@", arrayActions);
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (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.
}

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

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
	
	return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
	
	return [arrayActions count];
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
	
	return [arrayActions objectAtIndex:row];
}


- (void)dealloc {
   	[arrayActions release];
	[super dealloc];
}

header

Code:
@interface ActionsViewController : UIViewController {
	IBOutlet UIPickerView *pickerView;
	NSMutableArray *arrayActions;
	IBOutlet UIButton *aLoadButton;
}
 

TiberiusXavier

macrumors member
Apr 18, 2010
54
0
Chicago
Do you actually log the array out to the console? What does resp yield? You are also alloc/init a NSMutableArray (leaking?) but componentsSeparatedByString returns an NSArray type.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,425
A sea of green
arrayActions = [resp componentsSeparatedByString:mad:","];

That line of code is wrong. You're keeping a reference to an object you don't own. Either copy the object or retain it.

And be sure to release it when appropriate, because you're doing that wrong, too. This code leaks:
Code:
arrayActions = [[NSMutableArray alloc] init];
 

collinssol

macrumors newbie
Original poster
Oct 15, 2009
15
0
changes

Sorry on the leaking i though that was taken care of in the dealloc method

i changed the arrary to
Code:
arrayActions = [[NSArray alloc] init];

also changed the header

Same result
 

collinssol

macrumors newbie
Original poster
Oct 15, 2009
15
0
appreciate the response but i don't understand Either copy the object or retain it.
 

TiberiusXavier

macrumors member
Apr 18, 2010
54
0
Chicago
You shouldn't need to alloc/init the array. As chown33 alluded to already, try retaining the result:
Code:
arrayActions = [[resp componentsSeparatedByString:@","] retain];

(Remove the [[NSArray alloc] init]; line)
 

collinssol

macrumors newbie
Original poster
Oct 15, 2009
15
0
thanks

that did it. I appreciate the help and i will reread that memory document.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.