EXE_BAD_ACCESS help

Discussion in 'iOS Programming' started by collinssol, May 11, 2010.

  1. collinssol macrumors newbie

    Joined:
    Oct 15, 2009
    #1
    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;
    }
     
  2. TiberiusXavier macrumors member

    Joined:
    Apr 18, 2010
    Location:
    Chicago
    #2
    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.
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    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];
    
     
  4. collinssol thread starter macrumors newbie

    Joined:
    Oct 15, 2009
    #4
    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
     
  5. collinssol thread starter macrumors newbie

    Joined:
    Oct 15, 2009
    #5
    appreciate the response but i don't understand Either copy the object or retain it.
     
  6. TiberiusXavier macrumors member

    Joined:
    Apr 18, 2010
    Location:
    Chicago
    #7
    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)
     
  7. collinssol thread starter macrumors newbie

    Joined:
    Oct 15, 2009
    #8
    thanks

    that did it. I appreciate the help and i will reread that memory document.
     

Share This Page