Good afternoon, I have a button in my application that the value will change as the button is selected, it should open a field for the user to type and consequently he will get the value typed and change the label.
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var fieldInput: UITextField! // Campo
@IBOutlet weak var charOne: UIButton!
@IBOutlet weak var charTwo: UIButton!
@IBOutlet weak var charThree: UIButton!
@IBOutlet weak var charFour: UIButton!
var selectedButton: UIButton!
var savedText: String!
override func viewDidLoad() {
super.viewDidLoad()
// Atribuir delegate ao campo
fieldInput.isHidden = true
fieldInput.delegate = self
}
func textFieldShouldReturn(textFieldInput: UITextField) -> Bool
{
if (textFieldInput == self.fieldInput) {
// Guardar o texto do campo
savedText = textFieldInput.text
}
// Finalizar a edição
textFieldInput.resignFirstResponder()
return false;
}
@IBAction func didEditingEnd(sender: AnyObject) {
// Acção associada ao campo
selectedButton.setTitle(savedText, for: .normal)
fieldInput.isHidden = true
}
//UILongPressGestureRecognizer associado a cada botão
@IBAction func didLongPressButton(sender: AnyObject) {
if sender is UILongPressGestureRecognizer &&
sender.state == UIGestureRecognizerState.began {
if let button = sender.view! as? UIButton {
// Inicia alteração
fieldInput.isHidden = false
// Acção associada a cada botão
selectedButton = button
}
}
}
}
It's complaining about the view, I do not know what's wrong