【发布时间】:2014-09-12 13:06:54
【问题描述】:
我遇到了一个错误。我在地图中使用 OSM 磁贴,因为它们可以更好地显示我的位置。所以,我的viewDidLoad 是:
[super viewDidLoad];
self.mapView.delegate = self;
self.searchBar.delegate = self;
self.title = @"Select Location";
NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
overlay.canReplaceMapContent = YES;
[self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];
self.locationManager = [[CLLocationManager alloc] init];
if ( [CLLocationManager locationServicesEnabled] ) {
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 1000;
[self.locationManager startUpdatingLocation];
}
self.geocoder = [[CLGeocoder alloc] init];
...
好吧,错误出现了,当我尝试按返回或选择当前位置图钉时(我有一个 UIButton,在加载视图的所有图块之前。
我已经检查了this 的问题。并添加了这个:
- (void)viewWillDisappear:(BOOL)animated {
self.mapView = nil;
[super viewWillDisappear:animated];
}
我尝试在viewWillDisappear 和dealloc 中使用此代码,但似乎都不起作用。接下来,我已经覆盖了后退按钮操作,但仍然遇到此问题:
- (void)viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self] == NSNotFound) {
self.locationManager.delegate = nil;
self.mapView = nil;
self.searchBar.delegate = nil;
[self.navigationController popViewControllerAnimated:YES];
}
[super viewWillDisappear:animated];
}
据我所知,EXC_BAD_ACCESS 通常在尝试访问对象时出现,当它已经准备好被释放时。
如何正确释放所有数据?
更新:
异常出现在线:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
它出现在第一个线程中:
libobjc.A.dylib`objc_msgSend:
0x3b172620: cbz r0, 0x3b17265e ; objc_msgSend + 62
0x3b172622: ldr.w r9, [r0]
0x3b172626: ldrh.w r12, [r9, #12] <<<< Here
最后在 UIApplicationMain 中
0x3316e148: blx 0x33731cc4 ; symbol stub for: CFRunLoopSourceSignal$shim
0x3316e14c: movs r0, #0x0 <<< This line
UPD2: 好吧,在模拟器上与僵尸一起运行并检查堆栈显示了这样的事情:
据我了解,当 MKTileOverlay 尝试在已释放的 MapView 上加载图块时,就会出现问题。如何解决这个问题?
【问题讨论】:
-
你是否使用 arc 进行内存管理?
-
使用带有僵尸工具的工具并找出访问了哪个类?!
-
@Daij-Djan 如果我无法在模拟器中运行它怎么办(由于使用 parse.com iOS API 和 Mac 上的多个链接器错误)?
-
@Daij-Djan 好吧,我已经清理了依赖项的混乱。现在将尝试捕捉僵尸
-
@ka2m 你的异常回溯是没用的。您需要创建一个异常断点。请阅读文章My App Crashed, Now What?,它也在 ios-tag-wiki 中被引用(因为我几周前已经把它放在那里了。)如果你不使用调试器,每个异常似乎都在线
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));正确,因此它不会提供任何新的见解。
标签: ios objective-c exception mkmapview exc-bad-access