2016-07-29 89 views
0

我的应用程序本质上是一个卡片集合,每个卡片上都有各种消息/信息。人们通过这些卡片,通常向右滑动。我目前得到这个SIG ABRT错误:SIGABRT /无法识别的选择器

#import <UIKit/UIKit.h> 
#import "AppDelegate.h" 

int main(int argc, char * argv[]) { 
    @autoreleasepool { 
     return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 
    } 
} 

它还版画,这一点:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[filterPageViewController askForPushNotifications]: unrecognized selector sent to instance 0x7f8b6d0acd80' 
*** First throw call stack: 
(
    0 CoreFoundation      0x000000010fa92d85 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x000000010f506deb objc_exception_throw + 48 
    2 CoreFoundation      0x000000010fa9bd3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 
    3 CoreFoundation      0x000000010f9e1cfa ___forwarding___ + 970 
    4 CoreFoundation      0x000000010f9e18a8 _CF_forwarding_prep_0 + 120 
    5 Lettuce        0x000000010a2780a6 -[DraggableViewBackground cardSwipedRight:] + 2470 
    6 Lettuce        0x000000010a2d0ad5 -[DraggableView rightAction] + 453 
    7 Lettuce        0x000000010a2d02ed -[DraggableView afterSwipeAction] + 77 
    8 Lettuce        0x000000010a2cfe22 -[DraggableView beingDragged:] + 1922 
    9 UIKit        0x000000010d9c7b28 _UIGestureRecognizerSendTargetActions + 153 
    10 UIKit        0x000000010d9c419a _UIGestureRecognizerSendActions + 162 
    11 UIKit        0x000000010d9c2197 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 843 
    12 UIKit        0x000000010d9ca655 ___UIGestureRecognizerUpdate_block_invoke898 + 79 
    13 UIKit        0x000000010d9ca4f3 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 342 
    14 UIKit        0x000000010d9b7e75 _UIGestureRecognizerUpdate + 2634 
    15 UIKit        0x000000010d54448e -[UIWindow _sendGesturesForEvent:] + 1137 
    16 UIKit        0x000000010d5456c4 -[UIWindow sendEvent:] + 849 
    17 UIKit        0x000000010d4f0dc6 -[UIApplication sendEvent:] + 263 
    18 UIKit        0x000000010d4ca553 _UIApplicationHandleEventQueue + 6660 
    19 CoreFoundation      0x000000010f9b8301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    20 CoreFoundation      0x000000010f9ae22c __CFRunLoopDoSources0 + 556 
    21 CoreFoundation      0x000000010f9ad6e3 __CFRunLoopRun + 867 
    22 CoreFoundation      0x000000010f9ad0f8 CFRunLoopRunSpecific + 488 
    23 GraphicsServices     0x00000001107e2ad2 GSEventRunModal + 161 
    24 UIKit        0x000000010d4cff09 UIApplicationMain + 171 
    25 Lettuce        0x000000010a2c3f0f main + 111 
    26 libdyld.dylib      0x000000011012492d start + 1 
    27 ???         0x0000000000000001 0x0 + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

经过一番调查,我发现有问题的代码。这是我cardSwipedRight方法中的一条线,是我draggableviewbackground类(该类用作甲板,以容纳所有的卡):

   [((settingsTableViewController *)([obj.superNavController.viewControllers[obj.profileNum] viewControllers][0])) askForPushNotifications]; 

这行代码是检查这是否一个if语句中是“注册通知卡”。我感到困惑的是,为什么xcode与askForPushNotifications相关联的filterPageView。 filterPageView不仅没有askForPushNotifications方法,而且我也不会在filterPageView上滑动,也不会在应用程序崩溃时查看它。

+0

您的filterPageViewController是否有一个名为askForPushNotifications的方法? –

+0

不是它不 – Matt

+0

发现这样的错误。你在不应该的地方称呼它。 –

回答

0

一个接收一个无法识别的选择异常时发送的选择,选择器发送不执行对象/响应。简而言之,如果一个类A没有实现一个方法,并且有人试图在类A的一个对象上调用该方法,那么运行时会抛出一个无法识别的选择器异常。

当我们不确定对象是否会响应选择器时,我们应该进行安全检查以查看对象是否响应了预期的选择器。

例如,

if ([*obj* respondsToSelector:@selector(*selector*)]) 
{ 
    [*obj* performSelector:*selector*]; 
} 
+0

所以在我的askForPushNotifications方法中,我应该有这个if语句作为安全检查吗? – Matt

+0

或者我应该有这个if语句之前,“[((settingsTableViewController *)([obj.superNavController.viewControllers [obj。profileNum] viewControllers] [0]))askForPushNotifications]; “ – Matt

+0

是的,当你不确定对象是否会响应某个方法时,你应该总是** ** respondsToSelector **检查。这样你就可以避免这种类型的崩溃。 – Anup

0

当您尝试调用对象上的方法但该方法不存在时,发送给实例的无法识别的选择器出现(更正的术语是,您试图发送名为“askForPushNotifications”的消息,但settingsTableViewController不理解它,因为它(askForPushNotifications)不会退出。我相信你可能没有在你的settingsTableViewController中的方法。请检查并让我知道这是否对你有帮助。

此外,请检查与respondsToSelector,如果对象实际回应方法askForPushNotifications。可能是这种情况,

((settingsTableViewController *)([obj.superNavController.viewControllers[obj.profileNum] viewControllers][0]))

可能不是类型SettingsTableViewController。请检查

if [(((settingsTableViewController *)([obj.superNavController.viewControllers[obj.profileNum] viewControllers][0])) respondsToSelector:@selector(askForPushNotifications)] 
{ 
    [((settingsTableViewController *)([obj.superNavController.viewControllers[obj.profileNum] viewControllers][0])) askForPushNotifications]; 
} 
+0

askForPushNotifications是在我的settingsTableViewController虽然:/ – Matt

+0

它是否在.h文件中声明? –

+0

是的,它也在.h文件中声明 – Matt

相关问题