我有一个数组:
class viewController: UIViewController, UITextFieldDelegate {
private let textField = UITextField()
private let errorMessage = UILabel()
private let submitButton = UIButton()
override viewDidLoad() {
super.viewDidLoad()
/* setup your UI elements here */
setupTextField()
setupErrorMessage()
setupSubmitButton()
}
func setupTextField() {
/* setup your text field here (you did this already) */
}
func setupErrorMessage() {
/* Here, I am using AutoLayout to lay out the errorMessage on the screen.
If you used storyboard, delete every line in this function except where
we set the message to hidden */
errorMessage.translatesAutoResizingMaskIntoConstraints = false
errorMessage.text = "Error Message"
errorMessage.textColor = .red
errorMessage.isHidden = true
self.addSubView(errorMessage)
NSLayoutConstraints.activate([
textField.leadingAnchor.constraint(equalTo: textField.leadingAnchor),
textField.topAnchor.constraint(equalTo: textField.bottomAnchor, constant: 10.0)
])
}
func setupSubmitButton() {
/* setup your submit button here (you did this already) */
submitButton.addTarget(self, action: #selector(submitButtonPressed(_ :)), for: .touchUpInside)
}
@objc func submitButtonPressed() {
if textField.text.isEmpty {
errorMessage.isHidden = false
textField.layer.borderColor = .red
}
}
/* use a UITextFieldDelegate method to change the textField's border color
to blue again after the user has corrected the mistake
(for example, after the user starts typing into the textField again) */
func textFieldDidBeginEditing(_ textField: UITextField) {
textField.layer.borderColor = .blue
errorMessage.isHidden = true
}
}
我需要一种更快的方法将此数组重置为零。可以在渲染脚本中使用uint32_t a[65536];
吗?还是其他想法?