Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

unrecognised selector sent to instance

jarvjarv Posts: 210Registered Users @ @
Please help, I am having trouble actioning my button using UIBarButtonItem

My error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyWonders.AddWonderViewController addSaveButtonAction]: unrecognized selector sent to instance 0x7fd4dbe0fe50'

My code:
override func viewDidLoad() {

        // Do any additional setup after loading the view.
        let saveButton : UIBarButtonItem = UIBarButtonItem(title: "Save", style: UIBarButtonItemStyle.plain, target: self, action: Selector("addSaveButtonAction"))
        self.navigationItem.rightBarButtonItem = saveButton
    @IBAction func addSaveButtonAction(sender: UIButton!){
        wonderName = wonderNameTextField.text!
        wonderLatitude = Double(wonderLatitudeTextField.text!) ?? 0.0
        wonderLongitude = Double(wonderLongitudeTextField.text!) ?? 0.0
        wonderNotes = wonderNotesTextView.text!
        let wondersContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
        let newWonder = NSEntityDescription.insertNewObject(forEntityName: "Wonders", into: wondersContext) as! Wonders
        newWonder.wonderName = wonderName
        newWonder.wonderLatitude = wonderLatitude
        newWonder.wonderLongitude = wonderLongitude
        newWonder.wonderShow = true
        newWonder.wonderType = "MY"
            topSaveConfirmationLabel.text = "Saved" + wonderName
        } catch {
            topSaveConfirmationLabel.text = "Error" + wonderName
            print("Could not save \(error)")


Sign In or Register to comment.