简体   繁体   中英

Having issues in xcode 6.1 throws exception error

I am completely new here! Learning by the seat of my pants. Trying to create a login and Password screen with a label. I have a textfield for User Name, one for Password, a label that says "Please Login" and a button to push. Everything is fine until I get to the button. I drag the button to the screen and set it up how I want, but when I try to command left click drag the button to the code, I get no options to make it an action.

So it comes in as @IBOutlet var theButton: UIView! which is wrong. The only options I get is Outlet and Outlet Collections, I can type over UIView and make it UIButton.

So I manually type in :

@IBAction func theButton(sender: AnyObject) {
    var usr = "debf"
    var pw = "cando"

    if theTextfieldUsername.text == usr && theTextfieldPassword.text == pw {
        println("Login Sucessful")
        theTextfieldUsername.resignFirstResponder()
        theTextfieldPassword.resignFirstResponder()
    }
    else {
        println("Login Not Sucessful. Please Signup")
        theTextfieldUsername.resignFirstResponder()
        theTextfieldPassword.resignFirstResponder()
    }
}

And when I run it, it throws and exception and I can not figure out what the problem is! I get:

2014-10-24 17:45:23.096 UFMTest[4146:1713077] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UFMTest.ViewController 0x79c70990> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key theSubmitButt.'

theSubmitButt was the name of the button the first time I made it, I've deleted it and redone it several times but I still get this.

Any suggestions?

Here is the entire code:

//
//  ViewController.swift
//  UFMTest
//
//  Created by Deborah Flack on 10/24/14.
//  Copyright (c) 2014 Armidido Inc. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet var theTextfieldUsername: UITextField!
    @IBOutlet var theTextfieldPassword: UITextField!
    @IBOutlet var theLabel: UILabel!

    @IBAction func theButton(sender: AnyObject) {
        var usr = "debf"
        var pw = "cando"

        if theTextfieldUsername.text == usr && theTextfieldPassword.text == pw {
            println("Login Sucessful")
            theTextfieldUsername.resignFirstResponder()
            theTextfieldPassword.resignFirstResponder()
        }
        else {
            println("Login Not Sucessful. Please Signup")
            theTextfieldUsername.resignFirstResponder()
            theTextfieldPassword.resignFirstResponder()
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

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

The problem is, even after you deleted theSubmitButt code from from ViewController , Storyboard is still trying to connect the button to theSubmitButt .

To resolve that, check "Connection Inspector" out in Interface Builder, and disconnect it from theSubmitButt by clicking x button.

屏幕截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM