-1

I get this error every time I want to load a specific UIViewController

2016-04-09 20:48:02.183 myApp[91268:15399441] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key registerAction.' * First throw call stack: ( 0 CoreFoundation 0x000000010aaa6d85 exceptionPreprocess + 165 1 libobjc.A.dylib
0x000000010c84adeb objc_exception_throw + 48 2 CoreFoundation
0x000000010aaa69c9 -[NSException raise] + 9 3 Foundation
0x000000010ae7819b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 4 UIKit 0x000000010b461d0c -[UIViewController setValue:forKey:] + 88 5 UIKit 0x000000010b6987fb -[UIRuntimeOutletConnection connect] + 109 6
CoreFoundation 0x000000010a9e0890 -[NSArray makeObjectsPerformSelector:] + 224 7 UIKit
0x000000010b6971de -[UINib instantiateWithOwner:options:] + 1864 8
UIKit 0x000000010b4688d6 -[UIViewController _loadViewFromNibNamed:bundle:] + 381 9 UIKit 0x000000010b469202 -[UIViewController loadView] + 178 10 UIKit
0x000000010b469560 -[UIViewController loadViewIfRequired] + 138 11 UIKit 0x000000010b469cd3 -[UIViewController view] + 27 12 UIKit 0x000000010b33ffb4 -[UIWindow addRootViewControllerViewIfPossible] + 61 13 UIKit 0x000000010b34069d -[UIWindow _setHidden:forced:] + 282 14 UIKit 0x000000010b352180 -[UIWindow makeKeyAndVisible] + 42 15 UIKit
0x000000010b2c6ed9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131 16 UIKit 0x000000010b2cd568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769 17 UIKit 0x000000010b2ca714 -[UIApplication workspaceDidEndTransaction:] + 188 18 FrontBoardServices 0x000000010e6db8c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK
+ 24 19 FrontBoardServices 0x000000010e6db741 -[FBSSerialQueue _performNext] + 178 20 FrontBoardServices 0x000000010e6dbaca -[FBSSerialQueue _performNextFromRunLoopSource] + 45 21 CoreFoundation 0x000000010a9cc301 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 22 CoreFoundation 0x000000010a9c222c __CFRunLoopDoSources0 + 556 23 CoreFoundation 0x000000010a9c16e3 __CFRunLoopRun + 867 24 CoreFoundation
0x000000010a9c10f8 CFRunLoopRunSpecific + 488 25 UIKit
0x000000010b2c9f21 -[UIApplication _run] + 402 26 UIKit
0x000000010b2cef09 UIApplicationMain + 171 27 myApp
0x000000010a70dfb2 main + 114 28 libdyld.dylib
0x000000010dc6292d start + 1 29 ???
0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

the content inside the UIViewController ==>

import UIKit

class signUpPage: UIViewController {

@IBOutlet var emailTextField: UITextField!

@IBOutlet var passTextField: UITextField!
override func viewDidLoad() {
    self.viewDidLoad()
}
override func didReceiveMemoryWarning() {
    self.didReceiveMemoryWarning()
}

@IBAction func registerAction(sender: AnyObject) {
    let email = self.emailTextField.text
    let pass = self.passTextField.text
    if (email != "" && pass != ""){

        firebase_ref.createUser(email, password: pass, withValueCompletionBlock: { (error, results) in
            if (error == nil ){
                firebase_ref.authUser(email, password: pass, withCompletionBlock: { (error, authData) in
                    if (error == nil ){
                        NSUserDefaults.standardUserDefaults().setValue(authData.uid, forKey: "uid")
                        print("Account created Successfully ")
                        self.dismissViewControllerAnimated(true, completion: nil)
                    }else{
                        print(error.localizedDescription)
                    }
                })
            }else{
                print(error.localizedDescription)
            }
        })


    }else{
        let alert = UIAlertController(title: "Error", message: "Enter an email and password", preferredStyle: .Alert)
        let okAction = UIAlertAction(title: "ok", style: .Default, handler: nil)
        alert.addAction(okAction)
        self.presentViewController(alert, animated: true, completion: nil)
    }
}

@IBAction func cancleAction(sender: AnyObject) {

    self.dismissViewControllerAnimated(true, completion: nil )
}

} Thanks in advance for your help :)

rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

0

Looks like you don't have the IBAction registerAction connected to your xib.

Go to your xib for this UIViewController, control-click and drag from the button to File's Owner and you'll see a menu pop up with a list of your IBActions. Can select the correct one from the list to connect the button too.

Also if you may want to define the sender as a type instead of AnyObject.

enter image description here

Or you don't have the correct class connected to the xib

Click on File's Owner and make sure the correct class is in Identity Inspector:

enter image description here

Christopher Larsen
  • 1,375
  • 15
  • 22
-1
import UIKit

class signUpPage: UIViewController {

@IBOutlet var emailTextField: UITextField!

@IBOutlet var passTextField: UITextField!
override func viewDidLoad() {
self.viewDidLoad()
}
override func didReceiveMemoryWarning() {
self.didReceiveMemoryWarning()
}

@IBAction func registerAction(sender: AnyObject) {
let email = self.emailTextField.text
let pass = self.passTextField.text
if (email != "" && pass != ""){

    firebase_ref.createUser(email, password: pass, withValueCompletionBlock: { (error, results) in
        if (error == nil ){
            firebase_ref.authUser(email, password: pass, withCompletionBlock: { (error, authData) in
                if (error == nil ){
                    if (authData.uid != nil) {
    NSUserDefaults.standardUserDefaults().setValue(authData.uid, forKey: "uid")
}
                    print("Account created Successfully ")
                    self.dismissViewControllerAnimated(true, completion: nil)
                }else{
                    print(error.localizedDescription)
                }
            })
        }else{
            print(error.localizedDescription)
        }
    })


}else{
    let alert = UIAlertController(title: "Error", message: "Enter an email and password", preferredStyle: .Alert)
    let okAction = UIAlertAction(title: "ok", style: .Default, handler: nil)
    alert.addAction(okAction)
    self.presentViewController(alert, animated: true, completion: nil)
}
}

 @IBAction func cancleAction(sender: AnyObject) {

self.dismissViewControllerAnimated(true, completion: nil )
}
vaibby
  • 1,255
  • 1
  • 9
  • 23