我有一个带有按钮的tableView来推送mapView。推送和回退操作通常工作正常。如果我在这两个视图之间快速切换,则会出现“EXC_BAD_ACCESS”错误。当在tableView和mapView之间切换太快时出现“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
的main.m
#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:
的whereAmIAnnotation这里宣称:
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
正在下降崩溃。
您是否尝试插入断点并检查self.mapView和self.whereAmIAnnotation的值? 试着做一个简单的检查:if(self.mapView && self。whereAmIAnnotation)... –
你试过调试过吗?设置一个异常断点来查看崩溃正在发生哪一行? – Krishnabhadra
你如何设置self.mapView?它是一个IBOutlet吗?你是否通过代码来做到这一点。你能展示你如何设置和释放它吗? – iTukker