Question

I am trying to populate a UITableView with JSON, but when I reload the data of my table after making the connection it causes my app to crash, with error code

"Thread 1: EXC_BAD-ACCESS (code=1, address=0x0040da5)"

Here is my code:

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    data = [[NSMutableData alloc] init];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData {
[data appendData:theData];
}


-(void)connectionDidFinishLoading:(NSURLConnection *)connection {

[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

news = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
[mainTableView reloadData];


}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {

   UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not gather data, please make sure you're connected to either 3G or Wi-F" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
[errorView show];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

}
Was it helpful?

Solution

1> Are you sure you are getting news as expected by your table view ?

2> are you setting news to your datasource of the table before calling reload data

3> Please make sure you are extracting correct values from dictionary in your cellForIndexPath Method

The primary observation is that there is something wrong in cellForRowAtIndexPath and accessing the news array . Please check

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top