【问题标题】:iOS - Unable to locate the location of ExceptioniOS - 无法找到异常的位置
【发布时间】:2014-07-03 08:16:34
【问题描述】:

发生了什么?

我在一个程序中遇到一个异常,在该程序中,一个函数将被调用 On a Button 点击​​ contentView 的 UItableViewCell 内的自定义视图

我尝试了什么?

1) 我尝试在Breakpoints Navigator 中添加一个全局异常点

2) 从Instruments

检查僵尸检测

3) 应该调用的函数中的断点

我收到的崩溃日志?

-[UIImageView nextPage:]: unrecognized selector sent to instance 0xa7d5f20
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView nextPage:]: unrecognized selector sent to instance 0xa7d5f20'
*** First throw call stack:
(
    0   CoreFoundation                      0x023e11e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01fc98e5 objc_exception_throw + 44
    2   CoreFoundation                      0x0247e243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x023d150b ___forwarding___ + 1019
    4   CoreFoundation                      0x023d10ee _CF_forwarding_prep_0 + 14
    5   libobjc.A.dylib                     0x01fdb880 -[NSObject performSelector:withObject:withObject:] + 77
    6   UIKit                               0x009463b9 -[UIApplication sendAction:to:from:forEvent:] + 108
    7   UIKit                               0x00946345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    8   UIKit                               0x00a47bd1 -[UIControl sendAction:to:forEvent:] + 66
    9   UIKit                               0x00a47fc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
    10  UIKit                               0x00a47243 -[UIControl touchesEnded:withEvent:] + 641
    11  UIKit                               0x00cdc2e3 _UIGestureRecognizerUpdate + 7166
    12  UIKit                               0x00985a5a -[UIWindow _sendGesturesForEvent:] + 1291
    13  UIKit                               0x00986971 -[UIWindow sendEvent:] + 1021
    14  UIKit                               0x009585f2 -[UIApplication sendEvent:] + 242
    15  UIKit                               0x00942353 _UIApplicationHandleEventQueue + 11455
    16  CoreFoundation                      0x0236a77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    17  CoreFoundation                      0x0236a10b __CFRunLoopDoSources0 + 235
    18  CoreFoundation                      0x023871ae __CFRunLoopRun + 910
    19  CoreFoundation                      0x023869d3 CFRunLoopRunSpecific + 467
    20  CoreFoundation                      0x023867eb CFRunLoopRunInMode + 123
    21  GraphicsServices                    0x0381a5ee GSEventRunModal + 192
    22  GraphicsServices                    0x0381a42b GSEventRun + 104
    23  UIKit                               0x00944f9b UIApplicationMain + 1225
    24  IslamBox                            0x000029bc main + 76
    25  libdyld.dylib                       0x034b3701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

函数注册在 Nib 文件中,我还能做什么?

更新: 如日志所述 - [UIImageView nextpage] 无法识别,但下一页位于 ViewController 中。因为自定义视图是添加到单元格内容视图的 ViewController 的视图。

【问题讨论】:

  • 检查你调用 nextPage: 的位置。如果你添加你的代码,它会更好地帮助你。
  • 你能分享你的按钮选择器和cellForRowAtIndexPath的代码吗:
  • 在 cellForRowAtIndexPath 中有一个视图控制器,其视图被添加该控制器包含其功能定义
  • 其实在viewcontroller中注册了IBAction的View就是Button。但是日志说找不到 [UIImageView nextPage]。不应该是[viewcontroller nextPage]?
  • 请使用您的自定义视图实现和按钮选择器编辑您的答案。这将有助于其他人回答您的问题。

标签: ios iphone objective-c uitableview ios7


【解决方案1】:

我需要保留我的 ViewController ,或者在使用 ARC 时保留对它的强引用。如果我将它作为局部变量分配给 cell.contentView,那么当nextPage: 被调用时,它将不再存在。 (错误表明它的内存已被释放并重新用于不同类型的对象。)

【讨论】:

    【解决方案2】:

    难道只是您的 xib 文件中的对象设置为 UIImageView 而不是您自己的 UIImageView 的自定义子类吗?

    当视图从您的 xib 分配时,它将是一个 UIImageView。将其链接到 .h 或 .m 中的不同内容不会改变这一点。

    在此处更改:

    【讨论】:

    • 其实在viewcontroller中注册了IBAction的View就是Button。但是日志说找不到 [UIImageView nextPage]。不应该是[viewcontroller nextPage]?
    • 方法是 nextPage 还是 IBAction ?还是自己调用的方法?如果是,你可以分享你的代码部分,当nextPage被调用?
    • 是的,它是一个 IBAction,它在 InterfaceBuilder 中的 touchupinside 的 UIButton 上注册。所以没有代码可以分享但是可以分享截图
    • 我检查了视图是 UIButton,委托对象是视图控制器。太合乎逻辑了。
    • 检查我的答案我解决了。感谢您的帮助:)
    【解决方案3】:

    如果每次都在 [UIImageView nextPage:] 上崩溃, 你可以试试

    @implementation UIImageView(Test)
    
    - (id)nextPage:(id)noUse
    {
        return nil;
    }
    
    @end
    

    并在返回时设置断点。

    【讨论】:

    猜你喜欢
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 2019-05-05
    • 2015-05-13
    • 2018-08-31
    • 1970-01-01
    • 2018-08-03
    • 1970-01-01
    相关资源
    最近更新 更多