我有一个带有按钮的 tableView 来推送 mapView。push 和 back 动作通常可以正常工作。如果我在这两个视图之间快速切换,会出现“EXC_BAD_ACCESS”错误。
MapViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
UIButton *btnL = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40.0, 40.0)];
[btnL setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[btnL addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchDown];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:btnL] autorelease];
[btnL release];
self.whereAmIAnnotation = [[[WhereAmIAnnotation alloc] init] autorelease];
if (!self.mapView || !self.whereAmIAnnotation) {
NSLog(@"mapview : %@", self.mapView);
NSLog(@"whereAmIAnnotation : %@",self.whereAmIAnnotation);
// will never enter in to here
}
[self.mapView addAnnotation:self.whereAmIAnnotation];
}
如果我发表评论[self.mapView addAnnotation:self.whereAmIAnnotation];
,则不再有“EXC_BAD_ACCESS”。
任何答案和评论将不胜感激。提前致谢!
编辑 2
主文件
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
// "EXC_BAD_ACCESS" error message shows here
}
}
编辑3:
whereAmIAnotation 在这里声明:
MapViewController.m
@interface AddrCoordinateAdjustMapViewController()
@property (retain) WhereAmIAnnotation *whereAmIAnnotation;
@end
@implementation MapViewController
@synthesize whereAmIAnnotation;
编辑4:
错误信息如下:
2012-07-30 15:56:19.735 myApp[13584:707] *** -[MapViewController respondsToSelector:]: message sent to deallocated instance 0x10195e80
当我切换回正在下降的tableView
时候,它通常会崩溃。annotationView