I have the following code that creates a modal navigation controller and presents it.
DetailViewController *content = [[DetailViewController alloc]initWithNibName:@"DetailView" bundle:nil];
content.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Close"
style:UIBarButtonItemStylePlain
target:content
action:@selector(closeButtonPress:)] autorelease];
UIN开发者_如何转开发avigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:content];
modalNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:modalNavController animated:YES];
[modalNavController release];
This works fine 99% of the time but on the odd occasion I get a crash..
-[__NSCFType closeButtonPress:]: unrecognized selector sent to instance 0x5ca91d0
The code looks (almost) correct at first sight. But you should release content somewhere, but it's unlikely that the ExcBadAccess happens because of this.
So to hunt this down I would suggest to use NSZombies. NSZombies prevents that your objects get deallocated, they are just marked as deallocated (i.e. turned into zombies).
- Open the
Executable
group in your xcode (3.x) sidebar - Do a right-click and
Get Info
on your executable - Open the
Arguments
tab - Add a environment variable under
Variables to be set in the environment
- Name it
NSZombieEnabled
and set its value toYES
. Make sure that it is activated - Run your code with breakpoints enabled until the zombie object is called
When you know where it happens you can better investigate why it happens.
精彩评论