Swift:无法导航到另一个视图控制器

时间:2016-10-24 06:05:11

标签: ios swift uiviewcontroller

enter image description here

我真的不知道我在以下几行中犯了什么错误:

// Instantiate SecondViewController
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "RegistrationScreen2View") as! RegistrationScreen2ViewController
 self.navigationController?.pushViewController(secondViewController, animated: true)

我无法移动到故事板中的第二个视图控制器我已经提到RegistrationScreen2View

的故事板ID为RegistrationScreen2ViewController.

我收到以下异常:

2016-10-24 11:26:16.607 toadways[965:11142] -[toadways.RegistrationScreen1ViewController continue]: unrecognized selector sent to instance 0x7fe05dc34ec0
2016-10-24 11:26:16.619 toadways[965:11142] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[toadways.RegistrationScreen1ViewController continue]: unrecognized selector sent to instance 0x7fe05dc34ec0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010efa534b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010ea0621e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010f014f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x000000010ef2ac15 ___forwarding___ + 1013
    4   CoreFoundation                      0x000000010ef2a798 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x000000010f3cab88 -[UIApplication sendAction:to:from:forEvent:] + 83
    6   UIKit                               0x000000010f5502b2 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x000000010f5505cb -[UIControl _sendActionsForEvents:withEvent:] + 444
    8   UIKit                               0x000000010f54f4c7 -[UIControl touchesEnded:withEvent:] + 668
    9   UIKit                               0x000000010f4380d5 -[UIWindow _sendTouchesForEvent:] + 2747
    10  UIKit                               0x000000010f4397c3 -[UIWindow sendEvent:] + 4011
    11  UIKit                               0x000000010f3e6a33 -[UIApplication sendEvent:] + 371
    12  UIKit                               0x000000010fbd8b6d __dispatchPreprocessedEventFromEventQueue + 3248
    13  UIKit                               0x000000010fbd1817 __handleEventQueue + 4879
    14  CoreFoundation                      0x000000010ef4a311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    15  CoreFoundation                      0x000000010ef2f59c __CFRunLoopDoSources0 + 556
    16  CoreFoundation                      0x000000010ef2ea86 __CFRunLoopRun + 918
    17  CoreFoundation                      0x000000010ef2e494 CFRunLoopRunSpecific + 420
    18  GraphicsServices                    0x0000000116c0ca6f GSEventRunModal + 161
    19  UIKit                               0x000000010f3c8f34 UIApplicationMain + 159
    20  toadways                            0x000000010e2318bf main + 111
    21  libdyld.dylib                       0x000000011266368d start + 1
    22  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

请让我知道我在做什么错误。

1 个答案:

答案 0 :(得分:-1)

您的代码应该有效。最可能的是您忘记为目标ViewController输入Storyboard ID。

***如何解决:

在目标ViewController的Identity Inspector中,输入其ID。

enter image description here

相关问题