unrecognized selector sent to instance 0x7fd5966131a0"

I am trying to create a return button. But when simulating this error shows up
Check the connection of the button to its IBOutlet and IBAction.
Best would be to remove the connection anbd recreate.

If not enough, please show the code where crash occurs ?
If OK, don't forget to close the thread.
Hello Claude thanks for answering, but it wasn't clear in the following I will attach the code where the crash occurs import UIKit

class

SecondScreenViewController:

UIViewController {

  

    @IBAction func BackButton(_ sender: Any) {

        

        print("ButtonPressed")

    

    

    }

    

    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view.

    print("view has loaded")

}

When you paste code, use Paste and Match Style to avoid all the extra lines. And use Code formatter (<>) tool

Code Block
import UIKit
class SecondScreenViewController: UIViewController {
@IBAction func BackButton(_ sender: Any) {
print("ButtonPressed")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
print("view has loaded")
}
}

Where does crash occur ? Line 7 ?
What do you get printed on the console ? Please provide full copy.
Where is the button added ? In the viewController or in a navigation bar ?
Have you created a segue from the button ?

Did you check the connection from button in IB to its IBAction ? Maybe you have changed the name of the IBAction in code, directly, and not using the Refactor > Rename command ?

Best would be to :
  • remove the connection (In IB, open the connections Inspector, click on the x sign in front of backButton)

  • recreate the connection with control-drag

  • do an option clean build folder

Notes:
  • property and function names should always start with lowercase as backButton

  • backButton is not a very good name for an action (it is more for the outlet) ; you better name it just back or backAction if you prefer.

Did you solve your issue (you did not reply to the last answer nor closed the thread). That is not a very good practice on this forum.
Or maybe your question was not important at all for you ?
unrecognized selector sent to instance 0x7fd5966131a0"
 
 
Q