I am getting the following error:
* -[URLViewController respondsToSelector:]: message sent to deallocated instance 0xdb5c3b0
and I am quite confused on how to start debugging this. Can someone please give me some pointers on where to start to look at?
Here’s some code if you want to see. This is actually a URL interceptor, so that every links opens up in a presentModalViewController
- (BOOL)openURL:(NSURL *)url{
URLViewController * web = [[URLViewController alloc] init];
web.url = url;
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:web];
[nav.navigationBar setTintColor:[UIColor blackColor]];
[nav setModalPresentationStyle:UIModalPresentationFormSheet];
[self.detailViewController presentModalViewController:nav animated:NO];
[web release];
[nav release];
return YES;
}
If the URLViewController implementation is any interest, here it is:
@implementation URLViewController
@synthesize webview;
@synthesize url;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (IBAction) done:(id) sender
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction) openInSafari:(id) sender
{
[(CVore*)[CVore sharedApplication] openURL:url withOverride:NO];
}
- (void)dealloc
{
[super dealloc];
}
- (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.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.webview.delegate = self;
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webview loadRequest:requestObj];
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)]];
[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(openInSafari:)]];
// Do any additional setup after loading the view from its nib.
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString* title = [webView stringByEvaluatingJavaScriptFromString: @"document.title"];
self.title = title;
//self.navigationItem.title = title;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
@end
UPDATE:
After tracking this, I think my mistake here is I need to set UIWebView delegate to nil before the [super dealloc] is this correct? As when I did this, it no longer crashes
You’ve released your
URLViewControllerinstance to soon or you’ve not retained it. Also check for where you’ve used=instead of using the synthesized setter (potentially creating a zombie), if any. It’s hard to be helpful without any code to look at.__
When the
URLViewControllerhas been released and deallocated, yourwebviewreally should be too by the time you call tosuperbecause it’s a class member. However, objects must not retain their delegates (to prevent a “retain-cycle”) so if you’re some how putting an extra retain on your webview, here or elsewhere, its delegate can still end up being nil and give the resulting crash. For example, do you have aretainsynthesizer forwebview? And have you called this at any time?