Basically I am creating an app with the main view being a MKMapView where I need to show some annotations(of businesses, schools etc.).The annotations come from KML files that I retrieve ‘dynamically’ from a website.The second view, an UITableView, has the categories that represent annotations in the map.The selection of some categories, will lead to a string with their ID’s and when the Back button is clicked, this view should pass this string to the MapView, where it gets concatenated to another string that holds the other part of the ‘query string’, and so the KML file should be downloaded and its annotations viewed in the map.
There’s a problem,all the cells can be selected (checked), but when I click the Navigation Bar button ‘Back’ to go to the previous view, the app crashes.When I don’t select any cell and click the Back button, the app still crashes, but in the log file it tells me that the string I was passing to the previous view is nil.I have prepared the code for passing the parameter from one view to another, and don’t understand what is going wrong.I am posting code relevant only to the passing of the string between views.
GisListViewController.m :
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone ) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else if (cell.accessoryType == UITableViewCellAccessoryCheckmark ) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
NSMutableDictionary * myDictionary = [[NSMutableDictionary alloc] initWithCapacity:60];
int i = 0;
for (i = 0; i < [gisCategoryID count]; i++) {
[myDictionary setObject:[gisCategoryList objectAtIndex:i] forKey:[gisCategoryID objectAtIndex:i]];
NSMutableString *paramString2 = [[[NSMutableString alloc] init] autorelease];
[paramString2 appendFormat:@"%@&", [myDictionary objectForKey:[gisCategoryID objectAtIndex:i]]];
paramString = paramString2;
}
NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__);
}
- (void) viewWillDisappear:(BOOL) animated
{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
NSString *httpString = @"http://www.ikub.al/hartav2/handlers/kmlgenerator.ashx?layerid=";
NSString *finalkmlString = [ httpString stringByAppendingString:paramString ];
[[self delegate] setKmlString:finalkmlString];
NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__);
}
Hope it helps.
I guess Autorelease giving the problem.Try like this