我有一个应用程序显示地图和自定义注释.当用户触摸注释时,我的应用程序崩溃.它只发生在iOS 7中. iOS 6和iOS 5都能正常工作.

以下是控制台中显示的崩溃报告:

ERROR: Trying to select an annotation which has not been added
-[__NSSetM coordinate]: unrecognized selector sent to instance 0x18c9d580
*** Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: '-[__NSSetM coordinate]: unrecognized selector sent to instance 0x18c9d580'
*** First throw call stack:
(
    0   CoreFoundation                      0x020415e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x016918b6 objc_exception_throw + 44
    2   CoreFoundation                      0x020de903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0203190b ___forwarding___ + 1019
    4   CoreFoundation                      0x0206e46e __forwarding_prep_1___ + 14
    5   MapKit                              0x000de10c _Z21_insertionNodeForItemP11objc_objectP14MKQuadTrieNode + 50
    6   MapKit                              0x000de428 _Z9_containsP11objc_objectP14MKQuadTrieNode + 27
    7   MapKit                              0x000de8ed -[MKQuadTrie contains:] + 39
    8   MapKit                              0x000d4918 -[MKAnnotationManager selectAnnotation:animated:avoid:] + 116
    9   MapKit                              0x00090789 -[MKMapView handleTap:] + 541
    10  UIKit                               0x0056ae8c _UIGestureRecognizerSendActions + 230
    11  UIKit                               0x00569b00 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
    12  UIKit                               0x0056b56d -[UIGestureRecognizer _delayedUpdateGesture] + 60
    13  UIKit                               0x0056eacd ___UIGestureRecognizerUpdate_block_invoke + 57
    14  UIKit                               0x0056ea4e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
    15  UIKit                               0x00565148 _UIGestureRecognizerUpdate + 199
    16  CoreFoundation                      0x020094ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    17  CoreFoundation                      0x0200941f __CFRunLoopDoObservers + 399
    18  CoreFoundation                      0x01fe7344 __CFRunLoopRun + 1076
    19  CoreFoundation                      0x01fe6ac3 CFRunLoopRunSpecific + 467
    20  CoreFoundation                      0x01fe68db CFRunLoopRunInMode + 123
    21  GraphicsServices                    0x01f6c9e2 GSEventRunModal + 192
    22  GraphicsServices                    0x01f6c809 GSEventRun + 104
    23  UIKit                               0x001f2d3b UIApplicationMain + 1225
    24  CustomMKAnnotationView              0x0000285a main + 170
    25  CustomMKAnnotationView              0x000027a5 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException

而且我以下列方式创建了代码:

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
if ([view.annotation isKindOfClass:[BasicMapAnnotation class]])
    {
    if (_calloutAnnotation.coordinate.latitude == view.annotation.coordinate.latitude&&
        _calloutAnnotation.coordinate.longitude == view.annotation.coordinate.longitude)
    {
        return;
    }
    if (_calloutAnnotation)
    {
        [mapView removeAnnotation:_calloutAnnotation];
        _calloutAnnotation = nil;
    }
    _calloutAnnotation = [[[CalloutMapAnnotation alloc] 
                           initWithLatitude:view.annotation.coordinate.latitude
                          andLongitude:view.annotation.coordinate.longitude]autorelease];
    [mapView addAnnotation:_calloutAnnotation];

    [mapView setCenterCoordinate:_calloutAnnotation.coordinate animated:YES];
}else
{
    if([delegate respondsToSelector:@selector(customMKMapViewDidSelectedWithInfo:)])
    {
        [delegate customMKMapViewDidSelectedWithInfo:@"Annotation clicked"];
    }
}
}

-(void)mapView:(MKMapView *)mapView diddeselectAnnotationView:(MKAnnotationView *)view 
{
if (_calloutAnnotation&& ![view isKindOfClass:[CallOutAnnotationVifew class]])
{
    if (_calloutAnnotation.coordinate.latitude == view.annotation.coordinate.latitude&&
        _calloutAnnotation.coordinate.longitude == view.annotation.coordinate.longitude)
    {
        [mapView removeAnnotation:_calloutAnnotation];
        _calloutAnnotation = nil;
    }
}
}

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[CalloutMapAnnotation class]])
{

    CallOutAnnotationVifew *annotationView = (CallOutAnnotationVifew *)[mapView     dequeueReusableAnnotationViewWithIdentifier:@"CalloutView"];
    if (!annotationView)
    {
        annotationView = [[[CallOutAnnotationVifew alloc] initWithAnnotation:annotation reuseIdentifier:@"CalloutView"] autorelease];
        JingDianMapCell  *cell = [[[NSBundle mainBundle] loadNibNamed:@"JingDianMapCell" owner:self options:nil] objectAtIndex:0];
        cell.titleLable.text = @"Testing";
        [annotationView.contentView addSubview:cell];

    }
    return annotationView;
}else if ([annotation isKindOfClass:[BasicMapAnnotation class]])
{

     MKAnnotationView *annotationView =[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomAnnotation"];
    if (!annotationView)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation 
                                                       reuseIdentifier:@"CustomAnnotation"] autorelease];
        annotationView.canShowCallout = NO;
        annotationView.image = [UIImage imageNamed:@"pin.png"];
    }

    return annotationView;
}
return nil;
}

在didSelectAnnotationView和diddeselectAnnotationView中,我添加了新的注释视图,并删除了旧的注释视图.注释视图是自定义类.而_calloutAnnotation是CalloutMapAnnotation的一个对象,它是添加注释的NSObject类.

解决方法

_calloutAnnotation不包含注释视图.我认为你有某个代码像这样@prorerty(弱,非原子)MKAnnotation * calloutAnnotation;弱势强弱应该有所帮助.

ios – 用户触摸注释时遇到无法识别的选择器的更多相关文章

  1. 基于EJB技术的商务预订系统的开发

    用EJB结构开发的应用程序是可伸缩的、事务型的、多用户安全的。总的来说,EJB是一个组件事务监控的标准服务器端的组件模型。基于EJB技术的系统结构模型EJB结构是一个服务端组件结构,是一个层次性结构,其结构模型如图1所示。图2:商务预订系统的构架EntityBean是为了现实世界的对象建造的模型,这些对象通常是数据库的一些持久记录。

  2. js中‘!.’是什么意思

  3. InnoDB 和 MyISAM 引擎恢复数据库,使用 .frm、.ibd文件恢复数据库

  4. Error: Cannot find module ‘node:util‘问题解决

    控制台 安装 Vue-Cli 最后一步出现 Error: Cannot find module 'node:util' 问题解决方案1.问题C:\Windows\System32>cnpm install -g @vue/cli@4.0.3internal/modules/cjs/loader.js:638 throw err; &nbs

  5. yarn的安装和使用(全网最详细)

    一、yarn的简介:Yarn是facebook发布的一款取代npm的包管理工具。二、yarn的特点:速度超快。Yarn 缓存了每个下载过的包,所以再次使用时无需重复下载。 同时利用并行下载以最大化资源利用率,因此安装速度更快。超级安全。在执行代码之前,Yarn 会通过算法校验每个安装包的完整性。超级可靠。使用详细、简洁的锁文件格式和明确的安装算法,Yarn 能够保证在不同系统上无差异的工作。三、y

  6. 前端环境 本机可切换node多版本 问题源头是node使用的高版本

    前言投降投降 重头再来 重装环境 也就分分钟的事 偏要折腾 这下好了1天了 还没折腾出来问题的源头是node 使用的高版本 方案那就用 本机可切换多版本最终问题是因为nodejs的版本太高,导致的node-sass不兼容问题,我的node是v16.14.0的版本,项目中用了"node-sass": "^4.7.2"版本,无法匹配当前的node版本根据文章的提

  7. 宝塔Linux的FTP连接不上的解决方法

    宝塔Linux的FTP连接不上的解决方法常见的几个可能,建议先排查。1.注意内网IP和外网IP2.检查ftp服务是否启动 (面板首页即可看到)3.检查防火墙20端口 ftp 21端口及被动端口39000 - 40000是否放行 (如是腾讯云/阿里云等还需检查安全组)4.是否主动/被动模式都不能连接5.新建一个用户看是否能连接6.修改ftp配置文件 将ForcePassiveIP前面的#去掉 将19

  8. 扩展element-ui el-upload组件,实现复制粘贴上传图片文件,带图片预览功能

  9. 微信小程序canvas实现水平、垂直居中效果

    这篇文章主要介绍了小程序中canvas实现水平、垂直居中效果,本文图文实例代码相结合给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下

  10. 使用HTML5做的导航条详细步骤

    这篇文章主要介绍了用HTML5做的导航条详细步骤,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

随机推荐

  1. iOS实现拖拽View跟随手指浮动效果

    这篇文章主要为大家详细介绍了iOS实现拖拽View跟随手指浮动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  2. iOS – genstrings:无法连接到输出目录en.lproj

    使用我桌面上的项目文件夹,我启动终端输入:cd然后将我的项目文件夹拖到终端,它给了我路径.然后我将这行代码粘贴到终端中找.-name*.m|xargsgenstrings-oen.lproj我在终端中收到此错误消息:genstrings:无法连接到输出目录en.lproj它多次打印这行,然后说我的项目是一个目录的路径?没有.strings文件.对我做错了什么的想法?

  3. iOS 7 UIButtonBarItem图像没有色调

    如何确保按钮图标采用全局色调?解决方法只是想将其转换为根注释,以便为“回答”复选标记提供更好的上下文,并提供更好的格式.我能想出这个!

  4. ios – 在自定义相机层的AVFoundation中自动对焦和自动曝光

    为AVFoundation定制图层相机创建精确的自动对焦和曝光的最佳方法是什么?

  5. ios – Xcode找不到Alamofire,错误:没有这样的模块’Alamofire’

    我正在尝试按照github(https://github.com/Alamofire/Alamofire#cocoapods)指令将Alamofire包含在我的Swift项目中.我创建了一个新项目,导航到项目目录并运行此命令sudogeminstallcocoapods.然后我面临以下错误:搜索后我设法通过运行此命令安装cocoapodssudogeminstall-n/usr/local/bin

  6. ios – 在没有iPhone6s或更新的情况下测试ARKit

    我在决定下载Xcode9之前.我想玩新的框架–ARKit.我知道要用ARKit运行app我需要一个带有A9芯片或更新版本的设备.不幸的是我有一个较旧的.我的问题是已经下载了新Xcode的人.在我的情况下有可能运行ARKit应用程序吗?那个或其他任何模拟器?任何想法或我将不得不购买新设备?解决方法任何iOS11设备都可以使用ARKit,但是具有高质量AR体验的全球跟踪功能需要使用A9或更高版本处理器的设备.使用iOS11测试版更新您的设备是必要的.

  7. 将iOS应用移植到Android

    我们制作了一个具有2000个目标c类的退出大型iOS应用程序.我想知道有一个最佳实践指南将其移植到Android?此外,由于我们的应用程序大量使用UINavigation和UIView控制器,我想知道在Android上有类似的模型和实现.谢谢到目前为止,guenter解决方法老实说,我认为你正在计划的只是制作难以维护的糟糕代码.我意识到这听起来像很多工作,但从长远来看它会更容易,我只是将应用程序的概念“移植”到android并从头开始编写.

  8. ios – 在Swift中覆盖Objective C类方法

    我是Swift的初学者,我正在尝试在Swift项目中使用JSONModel.我想从JSONModel覆盖方法keyMapper,但我没有找到如何覆盖模型类中的Objective-C类方法.该方法的签名是:我怎样才能做到这一点?解决方法您可以像覆盖实例方法一样执行此操作,但使用class关键字除外:

  9. ios – 在WKWebView中获取链接URL

    我想在WKWebView中获取tapped链接的url.链接采用自定义格式,可触发应用中的某些操作.例如HTTP://我的网站/帮助#深层链接对讲.我这样使用KVO:这在第一次点击链接时效果很好.但是,如果我连续两次点击相同的链接,它将不报告链接点击.是否有解决方法来解决这个问题,以便我可以检测每个点击并获取链接?任何关于这个的指针都会很棒!解决方法像这样更改addobserver在observeValue函数中,您可以获得两个值

  10. ios – 在Swift的UIView中找到UILabel

    我正在尝试在我的UIViewControllers的超级视图中找到我的UILabels.这是我的代码:这是在Objective-C中推荐的方式,但是在Swift中我只得到UIViews和CALayer.我肯定在提供给这个方法的视图中有UILabel.我错过了什么?我的UIViewController中的调用:解决方法使用函数式编程概念可以更轻松地实现这一目标.

返回
顶部