每次我想加载特定的UIViewController
时都会出现此错误2016-04-09 20:48:02.183 myApp [91268:15399441] *终止app到期 未捕获的异常'NSUnknownKeyException',原因: '[setValue:forUndefinedKey:]:this class不是键值registerAction的键值编码兼容。 * 第一次抛出调用堆栈:(0 CoreFoundation 0x000000010aaa6d85 exceptionPreprocess + 165 1 libobjc.A.dylib
类型的未捕获异常
0x000000010c84adeb objc_exception_throw + 48 2 CoreFoundation
0x000000010aaa69c9 - [NSException raise] + 9 3基础
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视图] + 27 12 UIKit 0x000000010b33ffb4 - [UIWindow addRootViewControllerViewIfPossible] + 61 13 UIKit 0x000000010b34069d - [UIWindow _setHidden:强制:] + 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:终止于 NSException(lldb)
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 )
}
} 在此先感谢您的帮助:)
答案 0 :(得分:0)
看起来您没有将IBAction registerAction连接到您的xib。
转到你的xib获取这个UIViewController,按住Control键并从按钮拖动到File's Owner,你会看到一个菜单弹出一个你的IBActions列表。可以从列表中选择正确的连接按钮。
此外,如果您可能希望将发件人定义为类型而不是AnyObject。
或者您没有连接到xib的正确类
单击文件所有者,确保在Identity Inspector中使用正确的类:
答案 1 :(得分:-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 )
}