问题描述
我有一个带有按钮的tableView来推送mapView。推和后动作通常很好。如果我在这两个视图之间快速切换,则会出现EXC_BAD_ACCESS错误。
I have a tableView with an button to push a mapView. The push and back actions generally work fine. If I switch quickly between these two views, "EXC_BAD_ACCESS" error will appear.
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。
If I comment [self.mapView addAnnotation:self.whereAmIAnnotation];
, there is no "EXC_BAD_ACCESS" anymore.
任何答案和评论都将不胜感激。提前致谢!
Any answers and comments will be appreciated. Thanks in advance!
编辑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:
the whereAmIAnnotation is declared here:
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
它通常在我崩溃时崩溃当 annotationView
正在下降时,切换回 tableView
。
It usually crashes when i switch back to the tableView
while the annotationView
is dropping.
推荐答案
您是否已将自己移除为mapview的代表?
Have you removed yourself as delegate of the mapview?
self.mapview.delegate = nil;
尝试在viewWilldisappear或您认为必要的时候将其删除,因为如果您推动了查看控制器,稍后将返回视图。
try removing it at viewWilldisappear or whenever you consider necessary as you might need it later if you have pushed a view controller and will return to the view later.
简而言之,当您的视图无法响应委托时,请将其删除,这就是您获得EXC_BAD_ACCSS的原因。它向您的视图发送了一条消息,但它已经从内存中释放。
In a nutshell, remove it when your view cannot respond to the delegate which is why you got the EXC_BAD_ACCSS. it sent a message to your view but it was already released from memory.
这篇关于" EXC_BAD_ACCESS"在tableView和mapView之间切换太快时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!