I am working with a tabbar application. In one of the tabs I have a tableView controller embedded as a SplitView. When this tab becomes active i make a URL call to fetch some data from the server. I am not able to populate the data in the tableView. I have tried '[self.tableView reloadData]' but the application crashes. My ViewController class is subclassed to UITableViewController.
- (void)didReceiveUserListFromServer
{
NSData *jsonData = responseData;
NSError *error=nil;
NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONWritingPrettyPrinted error:&error];
userDetailsArray = [responseDict objectForKey:@"userDetails"];
NSLog(@"count===%d",[userDetailsArray count]); //This returns a non-zero number
[self.tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [userDetailsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ReturningPatientSearchResultCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSMutableDictionary *singleUserDetail = [userDetailsArray objectAtIndex:indexPath.row];
cell.textLabel.text=[singleUserDetail objectForKey:@"Name"]; //EXC_BAD_ACCESS here
return cell;
}
I'd try making the userDetailsArray
a strong property in your class and using self.userDetailsArray
for setting its value and references to it.
(It's odd that the array is valid for count
and not for a later access but released memory seems like the most logical explanation.)
You can also try turning on zombies for your build scheme and see if that provides better information.