【发布时间】:2015-08-12 22:10:32
【问题描述】:
我想知道如何在 UITextfield 中输入内容,然后通过 UIButton 将其发送到变量?
当我尝试使用此代码时,应用程序会自动崩溃并显示此错误:
线程:1 信号 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 中输入的文本设置什么? LabelHeure?
-
您的
Heure插座是否真的连接到界面生成器中的文本字段控件?在编辑器中它旁边应该有一个圆圈。空表示未连接,填充表示已连接。如果未连接,则会发生类似错误。
标签: iphone swift uibutton uitextfield uilabel