【发布时间】:2012-06-05 08:15:21
【问题描述】:
我有一个带有按钮的 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”了。
任何答案和 cmets 将不胜感激。提前致谢!
编辑 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.whereAmIAnotation 的值?尝试做一个简单的检查: if(self.mapView && self.whereAmIAnnotation)...
-
你试过调试吗?放一个异常断点,看看是哪一行发生了崩溃?
-
如何设置self.mapView?是 IBOutlet 吗?你是通过代码来做的吗?你能展示一下你是如何设置和释放它的吗?
-
@MarcoPace 请检查我的问题的更新
-
@iTukker 这是一个 IBOutlet。我从来没有释放它,因为它会自动释放。
标签: iphone ios mkmapview exc-bad-access