-3

I am trying to move from SignInViewController to RegisterUserViewController on button click .Here is code

   @IBAction func RegisterNewAccountButtonTapped(_ sender: Any) {
         print("Register account button tapped")
        //RegisterUserViewController


       // let storyboard = UIStoryboard(name: "SignInViewController", bundle: nil)
        let vc = self.storyboard?.instantiateViewController(withIdentifier: "RegisterUserViewController") as! RegisterUserViewController
        self.present(vc, animated: true)
    }

Here in this picture are the class and storyboard id enter image description here enter image description here Here is error that is coming on pressing Register New Account button .

   2018-04-27 06:09:24.720143-0700 UserRegistrationExample[10193:1788611] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UserRegistrationExample.RegisterUserViewController 0x7f84b4f171b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key repeatPasswordTextField.'
    *** First throw call stack:
    (
        0   CoreFoundation                      0x000000010db1826b __exceptionPreprocess + 171
        1   libobjc.A.dylib                     0x000000010a1fbf41 objc_exception_throw + 48
        2   CoreFoundation                      0x000000010db181b9 -[NSException raise] + 9
        3   Foundation                          0x0000000109c20883 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
        4   UIKit                               0x000000010a95dd56 -[UIViewController setValue:forKey:] + 87
        5   UIKit                               0x000000010ac3ac94 -[UIRuntimeOutletConnection connect] + 109
        6   CoreFoundation                      0x000000010dabb61d -[NSArray makeObjectsPerformSelector:] + 317
        7   UIKit                               0x000000010ac3964a -[UINib instantiateWithOwner:options:] + 1856
        8   UIKit                               0x000000010a964d49 -[UIViewController _loadViewFromNibNamed:bundle:] + 383
        9   UIKit                               0x000000010a965652 -[UIViewController loadView] + 177
        10  UIKit                               0x000000010a965983 -[UIViewController loadViewIfRequired] + 195
        11  UIKit                               0x000000010a9661e0 -[UIViewController view] + 27
        12  UIKit                               0x000000010b3bd39d -[_UIFullscreenPresentationController _setPresentedViewController:] + 89
        13  UIKit                               0x000000010a936a8f -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 133
        14  UIKit                               0x000000010a979338 -[UIViewController _presentViewController:withAnimationController:completion:] + 3808
        15  UIKit                               0x000000010a97c14a __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 134
        16  UIKit                               0x000000010a97c5ea -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 532
        17  UIKit                               0x000000010a97c086 -[UIViewController presentViewController:animated:completion:] + 181
        18  UserRegistrationExample             0x00000001098e0ae5 _T023UserRegistrationExample20SignInViewControllerC30RegisterNewAccountButtonTappedyypF + 1077
        19  UserRegistrationExample             0x00000001098e0c58 _T023UserRegistrationExample20SignInViewControllerC30RegisterNewAccountButtonTappedyypFTo + 72
        20  UIKit                               0x000000010a7cd631 -[UIApplication sendAction:to:from:forEvent:] + 83
        21  UIKit                               0x000000010a942000 -[UIControl sendAction:to:forEvent:] + 67
        22  UIKit                               0x000000010a94231d -[UIControl _sendActionsForEvents:withEvent:] + 450
        23  UIKit                               0x000000010a94124a -[UIControl touchesEnded:withEvent:] + 618
        24  UIKit                               0x000000010a840bf1 -[UIWindow _sendTouchesForEvent:] + 2807
        25  UIKit                               0x000000010a842314 -[UIWindow sendEvent:] + 4124
        26  UIKit                               0x000000010a7e82da -[UIApplication sendEvent:] + 352
        27  UIKit                               0x000000010b0f6f18 __dispatchPreprocessedEventFromEventQueue + 2809
        28  UIKit                               0x000000010b0f9a7f __handleEventQueueInternal + 5957
        29  CoreFoundation                      0x000000010dabb351 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
        30  CoreFoundation                      0x000000010db5ad71 __CFRunLoopDoSource0 + 81
        31  CoreFoundation                      0x000000010da9fcb9 __CFRunLoopDoSources0 + 185
        32  CoreFoundation                      0x000000010da9f29f __CFRunLoopRun + 1279
        33  CoreFoundation                      0x000000010da9eb29 CFRunLoopRunSpecific + 409
        34  GraphicsServices                    0x00000001101af9c6 GSEventRunModal + 62
        35  UIKit                               0x000000010a7cb9a4 UIApplicationMain + 159
        36  UserRegistrationExample             0x00000001098deee7 main + 55
        37  libdyld.dylib                       0x000000010ec3a621 start + 1
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException

I have visited the following links but non of them solved the problem

https://coderwall.com/p/cjuzng/swift-instantiate-a-view-controller-using-its-storyboard-name-in-xcode

instantiateViewControllerWithIdentifier - Storyboard id set but still not working

Present View Controller in Storyboard with a Navigation Controller - Swift

Swift 3, Xcode 8 Instantiate View Controller is not working

Instantiate and Present a viewController in Swift

How to remove this error.

You can download the code from this link .https://drive.google.com/open?id=1yUaKeI6ZQphN7CsoiaeF2p4TmW_B5-9u

  • 1
    The question you linked are not answering on the crash. That's the question you should look for = https://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key-v I guessed that you had previously an UITextField IBOutlet named `repeatPasswordTextField`, and you either removed it or renamed it. But you didn't redo/undo the link in the Storyboard/Interface Builder – Larme Apr 27 '18 at 13:41
  • 1
    The error probably means that `RegisterUserViewController` has an outlet called `repeatPasswordTextField` that is set up in the storyboard, but not in the code. – Andy Apr 27 '18 at 13:42

1 Answers1

0

Try CTRL and drag from your button to the next ViewController. Then select "show". This is how you set a segue. Then click on the segue and give him an identifier. Then you need to set the

 performSegue(withIdentifier: String, sender: self)

Have you tried this?

Developer Guy
  • 2,318
  • 6
  • 19
  • 37
Mastertrap
  • 59
  • 1
  • 11