我想知道如何在 UITextfield 中输入内容,然后通过 UIButton 将其发送到变量?
当我使用此代码尝试时,应用程序会自动崩溃并显示此错误:
Thread:1 signal SIGABRT
代码如下:
import UIKit
import Foundation
class ViewController: UIViewController {
@IBOutlet weak var LabelHeure: UILabel!
@IBOutlet weak var Heure: UITextField!
@IBAction func Send(sender: AnyObject) {
var one = String(Heure.text)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
LabelHeure.text = NSDateFormatter.localizedStringFromDate(NSDate(),dateStyle:NSDateFormatterStyle.MediumStyle,timeStyle: NSDateFormatterStyle.NoStyle)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
最佳答案
您不需要将 Heure.text 转换为字符串,因为它已经是一个字符串。
关于iphone - 如何通过 UIButton 将 UITextfield 发送到变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31976270/