对于关键用户名

时间:2017-04-19 14:32:58

标签: swift3

this is my project file我是初学者,这是我的第一个应用,所以请简单解释一下。
我已经检查了我的usernameTextField连接到@IBOutlet,甚至删除了它并重新连接了很多次但仍然是同样的错误:

2017-04-19 21:34:27.957164 + 0430 Cactus-LoginRegister [774:12760] [MC] systemgroup.com.apple.configurationprofiles路径的系统组容器是/ Users / shamymash / Library / Developer / CoreSimulator /设备/ 19D0A023-F7CC-4813-B35E-1452B3BA4F07 /数据/容器/共享/ SystemGroup / systemgroup.com.apple.configurationprofiles 2017-04-19 21:34:27.957557 + 0430 Cactus-LoginRegister [774:12760] [MC]从私人有效用户设置中读取。 2017-04-19 21:34:35.582 Cactus-LoginRegister [774:12760] *由于未捕获的异常终止应用程序' NSUnknownKeyException',原因:' [valueForUndefinedKey:]:此类密钥用户名不符合密码值编码。' * 第一次抛出调用堆栈: (     0 CoreFoundation 0x0000000104fd6b0b exceptionPreprocess + 171     1 libobjc.A.dylib 0x0000000104a3b141 objc_exception_throw + 48     2 CoreFoundation 0x0000000104fd6a59 - [NSException raise] + 9     3基金会0x0000000104619731 - [NSObject(NSKeyValueCoding)valueForUndefinedKey:] + 226     4基金会0x0000000104548e1d - [NSObject(NSKeyValueCoding)valueForKey:] + 284     5 Cactus-LoginRegister 0x0000000104458394 _TFC20Cactus_LoginRegister26RegisterPageViewController20registerButtonTappedfP_T_ + 3092     6 Cactus-LoginRegister 0x00000001044595c3 _TToFC20Cactus_LoginRegister26RegisterPageViewController20registerButtonTappedfP_T_ + 67     7 UIKit 0x00000001053fbd22 - [UIApplication sendAction:to:from:forEvent:] + 83     8 UIKit 0x000000010558025c - [UIControl sendAction:to:forEvent:] + 67     9 UIKit 0x0000000105580577 - [UIControl _sendActionsForEvents:withEvent:] + 450     10 UIKit 0x000000010557f4b2 - [UIControl touchesEnded:withEvent:] + 618     11 UIKit 0x000000010546949a - [UIWindow _sendTouchesForEvent:] + 2707     12 UIKit 0x000000010546abb0 - [UIWindow sendEvent:] + 4114     13 UIKit 0x00000001054177b0 - [UIApplication sendEvent:] + 352     14 UIKit 0x0000000105bfaadc __dispatchPreprocessedEventFromEventQueue + 2926     15 UIKit 0x0000000105bf2a3a __handleEventQueue + 1122     16 CoreFoundation 0x0000000104f7cc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17     17 CoreFoundation 0x0000000104f620cf __CFRunLoopDoSources0 + 527     18 CoreFoundation 0x0000000104f615ff __CFRunLoopRun + 911     19 CoreFoundation 0x0000000104f61016 CFRunLoopRunSpecific + 406     20 GraphicsServices 0x00000001095b4a24 GSEventRunModal + 62     21 UIKit 0x00000001053fa0d4 UIApplicationMain + 159     22 Cactus-LoginRegister 0x0000000104456ba7 main + 55     23 libdyld.dylib 0x000000010864965d start + 1     24 ??? 0x0000000000000001 0x0 + 1 ) libc ++ abi.dylib:以NSException类型的未捕获异常终止 (lldb)

类RegisterPageViewController:UIViewController {

@IBOutlet weak var usernameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var repeatPasswordTextField: UITextField!


override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}



@IBAction func registerButtonTapped(_ sender: Any) {

    let username = usernameTextField.text
    let password = passwordTextField.text
    let repeatPassword = repeatPasswordTextField.text


    //Check for empty fields

    if (username!.isEmpty || password!.isEmpty || repeatPassword!.isEmpty) {

        //Display alert

        displayMyAlertMessage(userMessage: "All fields are required!")

        return
    }

    //Check if passwords match

    if(password != repeatPassword){

        //Display an alert

        displayMyAlertMessage(userMessage: "Passwords do not match")

        return



    }

    //Store data

    UserDefaults.standard.set(username,forKey: value(forKey: "username") as! String)
    UserDefaults.standard.set(password,forKey: value(forKey: "password") as! String)

    UserDefaults.standard.synchronize()

    //Display alert message with confirmation

    let myAlert = UIAlertController(title: "Alert", message: "Registration has succeeded. Thank you! ", preferredStyle: UIAlertControllerStyle.alert)
    let okAction = UIAlertAction(title:"ok", style:UIAlertActionStyle.default){ action in
    self.dismiss(animated: true, completion: nil)

    }

    myAlert.addAction(okAction)
    self.present(myAlert, animated: true, completion: nil)

}


func displayMyAlertMessage(userMessage:String) {

    let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.alert)

    let okAction = UIAlertAction(title:"ok", style:UIAlertActionStyle.default, handler:nil)

    myAlert.addAction(okAction)

    self.present(myAlert, animated: true, completion: nil)
}

}

0 个答案:

没有答案