我正在尝试将我已设置的文本字段中的输入打印到控制台,然后再将其打印到标签上。我已经尝试过字符串插值和其他各种方法,但我似乎无法自己打印输入。我知道力量展开是不受欢迎的,但是在我开始工作之后我会正确处理它。我已经检查过其他问题,但没有找到具体的内容
为了更清楚,当我按提交时,我希望文本字段中的文本打印到控制台。现在发生的事情是值只出现在(UITextfield)
class SPProfileViewController: UIViewController {
@IBOutlet weak var typeOfCompany: UITextField!
@IBOutlet weak var firstName: UITextField!
@IBOutlet weak var lastName: UITextField!
@IBOutlet weak var email: UITextField!
@IBOutlet weak var cellPhone: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
typeOfCompany.delegate = self
firstName.delegate = self
lastName.delegate = self
email.delegate = self
cellPhone.delegate = self
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
cellPhone.resignFirstResponder()
}
@IBAction func onSubmit(_ sender: UITextField) {
print(self.typeOfCompany.text!)
print(self.firstName.text!)
print(self.lastName.text!)
print(self.email.text!)
print(self.cellPhone.text!)
}
}
extension SPProfileViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}
答案 0 :(得分:1)