我有一个带有按钮的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下降时,它通常会崩溃。
发布于 2014-11-18 08:39:39
我也有类似的问题,我的解决方案是在从UINavigationController中弹出控制器之前从地图中删除所有的覆盖。我在用OpenStreetMap。
https://stackoverflow.com/questions/10893808
复制相似问题