Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用SWITCH和uiTextfield变量更新swift中的标签_Ios_Swift_Switch Statement_Case - Fatal编程技术网

Ios 如何使用SWITCH和uiTextfield变量更新swift中的标签

Ios 如何使用SWITCH和uiTextfield变量更新swift中的标签,ios,swift,switch-statement,case,Ios,Swift,Switch Statement,Case,我想制作一个小程序,当一个人在文本字段中键入“happy”或“sad”时,标签会根据情况进行更新,并显示一些内容。。。这是我的密码: class ViewController: UIViewController { @IBOutlet weak var aiAnswer: UILabel! @IBOutlet weak var humanResponse: UITextField! // when user taps submit run this @IB

我想制作一个小程序,当一个人在文本字段中键入“happy”或“sad”时,标签会根据情况进行更新,并显示一些内容。。。这是我的密码:

class ViewController: UIViewController {

    @IBOutlet weak var aiAnswer: UILabel!

    @IBOutlet weak var humanResponse: UITextField!

    // when user taps submit run this

    @IBAction func responseRequest(sender: AnyObject) {

    // check the variable humanResponse to see if they typed happy or sad and update the UI label based on that

        switch (humanResponse) {

        case "happy":

                aiAnswer.text = "thats great your happy!";

        case "sad":

                aiAnswer.text = "thats no fun!";

        default:

                aiAnswer.text = "please input a valid emotions";




        }


    }

我认为您的
开关有问题。更新如下:

switch humanResponse.text! {   //text entered by user

    case "happy":

        aiAnswer.text = "thats great your happy!";

    case "sad":

        aiAnswer.text = "thats no fun!";

    default:

        aiAnswer.text = "please input a valid emotions";

    }