我有一个以 MKMapView 作为其子视图的视图。由于我的地图空间不大,我阻止了与地图的所有交互,例如滚动、缩放等。相反,当用户点击地图时(实际上他点击了地图上的一个不可见按钮),我使用位置设置。这工作正常。
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:zoomLocation addressDictionary:nil];
self.mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
self.mapItem.name = @"name of the place";
UIButton *overlayButton = [UIButton buttonWithType:UIButtonTypeCustom];
overlayButton.frame = self.bounds;
overlayButton.backgroundColor = [UIColor clearColor];
overlayButton.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[overlayButton addTarget:self action:@selector(didTapOverlayButton) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:overlayButton];
didTapOverlayButton 导致它被执行:
[self.mapItem openInMapsWithLaunchOptions:nil];
现在我不想在没有警告他的情况下将用户踢出我的应用程序并打开另一个应用程序,所以我添加了一个 UIAlertView。现在 didTapOverlayButton 看起来像这样:
- (void)didTapOverlayButton {
UIAlertView *mapOpenAlert = [[UIAlertView alloc] initWithTitle:nil message:@"Do you want to open maps to see this location's details?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
[mapOpenAlert show];
}
现在,当我单击其中一个按钮时,我的应用程序将关闭(如果我单击“是”,它将打开地图,但仍会关闭)。没有显示错误,日志中没有任何内容,没有内存警告。self(警报视图的委托)未发布,我的类被声明为符合 UIAlertViewDelegate 协议。
我的委托人的方法:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != alertView.cancelButtonIndex) {
[self openExternalMap];
}
}
- (void)openExternalMap {
[self.mapItem openInMapsWithLaunchOptions:nil];
}
在 iOS 6 和 7 上测试。
编辑:我在控制台中得到这个:
2 月 20 日 16:14:31 iPhone-Devices com.apple.debugserver-300.2[6048] : 1 +0.000000 sec [17a0/1307]: error: ::read (-1, 0x3169ec, 18446744069414585344) => -1 err =错误的文件描述符 (0x00000009)
2 月 20 日 16:14:31 iPhone-Devices com.apple.debugserver-300.2[6048]:退出。