使用 Swift 将输入从 TextField 打印到 Xcode 中的标签 [英] Printing input from TextField to a Label in Xcode with Swift
本文介绍了使用 Swift 将输入从 TextField 打印到 Xcode 中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个简单的猜谜游戏应用程序,只是为了更好地使用 Swift 和 Xcode.我已经能够在 userInput 中输入并让它向控制台打印一条消息,但是当我尝试让它将我的输入打印到 usersGuess(这是一个标签)时,我无法弄清楚.
I'm working on a simple guessing game app, just to get more comfortable with Swift and Xcode. I have been able to input within userInput and get it to print a message to the console, however when I try to get it to print my input to usersGuess(which is a label), I can not figure it out.
这是我通过 Xcode 在单视图应用程序中的代码:
Here's my code within a single view application via Xcode:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var correctAnswerLabel: UILabel!
@IBOutlet weak var usersGuess: UILabel!
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.
}
@IBAction func buttonPressed() {
correctAnswerLabel.text = "Changes when the button is pressed."
}
@IBAction func userInput(sender: UITextField) {
println("This is working")
}
}
我确定这很简单,但我正在挠头哈哈.
I'm sure this is simple, but I am scratching my head lol.
推荐答案
@IBAction func userInput(sender: UITextField) {
println("This is working")
usersGuess.text = sender.text
}
这篇关于使用 Swift 将输入从 TextField 打印到 Xcode 中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文