【发布时间】:2015-09-18 16:46:44
【问题描述】:
我想制作一个小程序,当一个人在文本字段中输入“快乐”或“悲伤”时,标签会根据情况更新并说些什么……这是我的代码:
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";
}
}
【问题讨论】:
标签: ios swift switch-statement case