I have a UIViewController that I am presenting modally. I use this in several places and all except 1 work perfectly. In this one case the app crashes with a Bad Access when the modal view is dismissed. The culprit appears to be the release of the UIViewController. It is not crashing on any line of my code so has been very difficult to trace.
The ViewController implements a delegate protocol with a call back for dismissal, and I am presenting the view like this...
The call back looks like this..
As is, this will crash, but if I remove [locationSearchViewController release] from the picture it works fine and "Build and Analyze" reports no issues. It also crashes if I use autorelease or move the release to the call back.
Again it works fine with the release in other places that I am using this view. There is a difference in the way this particular implementation of the view is presented from the others. In the other cases I am presenting the view from the root view controller or from another modal view. In this case there is a modal view with a navigation bar that pushes another view on to the stack and from there the problem view is presented.
Bottom line my question is, should I be worried about this anomaly? Or, just don't release the view in this one case and forget about it?
Thanks for any suggestions.
John
The ViewController implements a delegate protocol with a call back for dismissal, and I am presenting the view like this...
Code:
- (void)tableView:(UITableView *)tableView
LocationSearchViewController *locationSearchViewController = [[LocationSearchViewController alloc] initWithNibName:@"LocationSearchViewController" bundle:nil];
locationSearchViewController.delegate = self;
UITableViewCell *cell = [myTableView cellForRowAtIndexPath:indexPath];
locationSearchViewController.defaultLocation = cell.textLabel.text;
[self presentModalViewController:locationSearchViewController animated:YES];
[locationSearchViewController release];
}
The call back looks like this..
Code:
- (void)locationSearchViewDidDismiss:(LocationSearchViewController *)controller withLocation:(NSString*)location
{
[self dismissModalViewControllerAnimated:YES];
if(location != @""){
[lastLocation replaceObjectAtIndex:0 withObject:location];
[myTableView reloadData];
}
}
As is, this will crash, but if I remove [locationSearchViewController release] from the picture it works fine and "Build and Analyze" reports no issues. It also crashes if I use autorelease or move the release to the call back.
Again it works fine with the release in other places that I am using this view. There is a difference in the way this particular implementation of the view is presented from the others. In the other cases I am presenting the view from the root view controller or from another modal view. In this case there is a modal view with a navigation bar that pushes another view on to the stack and from there the problem view is presented.
Bottom line my question is, should I be worried about this anomaly? Or, just don't release the view in this one case and forget about it?
Thanks for any suggestions.
John