1

当尝试将我的 JSON 文件中的值发送到另一个 ViewController 中的字符串时,我最终收到此错误:

2013-08-05 08:15:50.597 AHMC[11304:70b] -[UINavigationController setSessionKey:]: unrecognized selector sent to instance 0x898d3f0
2013-08-05 08:15:50.600 AHMC[11304:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setSessionKey:]: unrecognized selector sent to instance 0x898d3f0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0172eed4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014af8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x017cbb83 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0171f1fb ___forwarding___ + 1019
    4   CoreFoundation                      0x0171edde _CF_forwarding_prep_0 + 14
    5   AHMC                                0x00008013 -[LoginViewController loginAction:] + 963
    6   libobjc.A.dylib                     0x014c1874 -[NSObject performSelector:withObject:withObject:] + 77
    7   UIKit                               0x0023c968 -[UIApplication sendAction:to:from:forEvent:] + 108
    8   UIKit                               0x0023c8f4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    9   UIKit                               0x00330581 -[UIControl sendAction:to:forEvent:] + 66
    10  UIKit                               0x00330944 -[UIControl _sendActionsForEvents:withEvent:] + 577
    11  UIKit                               0x0032fbf3 -[UIControl touchesEnded:withEvent:] + 641
    12  UIKit                               0x0027956d -[UIWindow _sendTouchesForEvent:] + 852
    13  UIKit                               0x0027a172 -[UIWindow sendEvent:] + 1134
    14  UIKit                               0x0024df06 -[UIApplication sendEvent:] + 242
    15  UIKit                               0x00238b0f _UIApplicationHandleEventQueue + 11421
    16  CoreFoundation                      0x016b817f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    17  CoreFoundation                      0x016b7b0b __CFRunLoopDoSources0 + 235
    18  CoreFoundation                      0x016d4bde __CFRunLoopRun + 910
    19  CoreFoundation                      0x016d4403 CFRunLoopRunSpecific + 467
    20  CoreFoundation                      0x016d421b CFRunLoopRunInMode + 123
    21  GraphicsServices                    0x03697a37 GSEventRunModal + 192
    22  GraphicsServices                    0x0369785e GSEventRun + 104
    23  UIKit                               0x0023b6bb UIApplicationMain + 1225
    24  AHMC                                0x00009d8d main + 141
    25  libdyld.dylib                       0x01d6b70d start + 1
    26  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

这是将变量的新值发送到下一个视图控制器上的变量的代码。

FirstViewController *dash = [self.storyboard instantiateViewControllerWithIdentifier:@"dashboard"];

    dash.sessionKey = [jsonArray objectForKey:@"new_session_key"];

我通过使用 NSLog 进行测试来验证 new_session_key 的值是“262040c7c199e59abfe78009f3ecd8”。

是的,我在第二个视图的头文件中创建了变量:

 @interface FirstViewController : UIViewController
{
    NSString *sessionKey;
}

@property (nonatomic, retain) NSString *sessionKey;

请协助我为什么会收到此错误。

4

1 回答 1

3

如果您仔细查看错误的第一行,

-[UINavigationController setSessionKey:]: unrecognized selector sent to instance 0x898d3f0

因此,与其调用 FirstViewController 的 sessionKey 属性,不如尝试为 UINavigationController 调用它,这就是您崩溃的原因。

我会要求您检查 FirstViewController 的 Storyboard ID... 我相信您正在使用 UINavigationController => "dashboard" 的 Storyboard ID

我希望它有助于解决崩溃

于 2013-08-05T12:27:58.983 回答