ios - 单击按钮时 UIAlertView 静默崩溃

标签 ios objective-c mapkit uialertview mkmapitem

我有一个以 MKMapView 作为其 subview 的 View 。由于我的 map 空间不大,所以我阻止了与 map 的所有交互,例如滚动、缩放等。相反,当用户点击 map 时(实际上他点击了 map 上的一个不可见按钮),我使用以下命令打开Apple Maps:位置设置。这很好用。

    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];
}

现在,当我单击其中一个按钮时,我的应用程序将关闭(如果我单击"is",它将打开 map ,但仍然关闭)。没有显示错误,日志中没有任何内容,没有内存警告。 self(警报 View 的委托(delegate))未释放,我的类被声明为符合 UIAlertViewDelegate 协议(protocol)。

我的委托(delegate)方法:

- (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 秒 [17a0/1307]: 错误:::read ( -1, 0x3169ec, 18446744069414585344 ) => - 1 err = 错误文件描述符 (0x00000009)

2 月 20 日 16:14:31 iPhone-Devices com.apple.debugserver-300.2[6048]:退出。

最佳答案

我很确定这是 iOS7 中的一个错误 - 我在测试版期间注意到了它,看起来它从未被修复过。我建议在 Apple 提交错误报告:

https://developer.apple.com/bug-reporting/

关于ios - 单击按钮时 UIAlertView 静默崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21907912/

相关文章:

ios - iOS-CGImageRef潜在泄漏

ios - 使用委托(delegate)将值保存到核心数据

ios - 在 iOS 中使用 AFNetworking 2 检查连接的最佳方法?

swift - 如何以相同的顺序检索坐标?

ios - Sprite Kit - 检测接触

iphone - 在单键 NSMutableDictionary 下添加两个对象

iphone - 从 AFImageRequestOperation 中的成功 block 返回图像

iPhone/Objective-C - 更改默认 "navigationItem.prompt"颜色

ios - 如何检查 locationManager 是否更新了当前位置?

ios - 如何在 MapKit 中绘制带有外边框的叠加层?