I'm trying to make a kind of conditional segue through the "shouldPerformSegueWithIdentifier" override function, and it reports the error "Method does not override any method from its superclass" and tells me to remove the "override" word. When I do so, it reports the next error:
"Method 'shouldPerformSegueWithIdentifier(:sender:)' with Objective-C selector 'shouldPerformSegueWithIdentifier:sender:' conflicts with method 'shouldPerformSegueWithIdentifier(:sender:)' from superclass 'UIViewController' with the same Objective-C selector".
This is my code now:
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
//MARK: Propierties
@IBOutlet weak var whateverLabel: UILabel!
@IBOutlet weak var errorMessageLabel: UILabel!
@IBOutlet weak var textFieldRandomWord: UITextField!
//MARK: Actions
@IBAction func printWhatever(sender: UIButton) {whateverLabel.text = "Whatever"
}
@IBOutlet weak var goOnButton: UIButton!
override func shouldPerformSegueWithIdentifier(identifier: String, sender: UIButton?) -> Bool {
if identifier == "firstsegue" && sender == goOnButton { // you define it in the storyboard (click on the segue, then Attributes' inspector > Identifier
if textFieldRandomWord.text == "Whatever" {
errorMessageLabel.textColor = UIColor .redColor()
errorMessageLabel.text = "*** NOPE, segue wont occur"
return false
}
else {
errorMessageLabel.text = "*** YEP, segue will occur"
}
}
// by default, transition
return true
}
override func viewDidLoad() {
super.viewDidLoad()
textFieldRandomWord.delegate = self //ViewController is textFieldRandomWord's delegate, so "self" reffers to itself (ViewController)//
}
//MARK: UITextFieldDelegate
func textFieldShouldReturn(textField: UITextField) -> Bool {
//Hide the keyboard.
textFieldRandomWord.resignFirstResponder()
return true}
func textFieldDidEndEditing(textField: UITextField){
whateverLabel.text = textFieldRandomWord.text}
//Above, the textFieldShouldReturn function makes the text field inactive when return (enter) is pressed. The last function gets activated automatically when this happens.//
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}