swifteureka-forms

Swift: Dismiss a FormViewController in Eureka-forms


I'm reasonably new with Eureka forms for Swift (fantastic library by the way) - but I'm having trouble working out how to dismiss a FormViewController that is presented via a show segue.

I have a button Row in the FormViewController, which fires off a POST and then calls the delegate method to dismiss the FormViewController from the presenting view controller. This delegate method fires off OK, but the FormViewController does not get dismissed.

I've looked around the documentation and have done some searching, but I can't seem to find the right info. Here's an image of the FormViewController "stuck" after it should have been dismissed: https://i.sstatic.net/O3Xci.png

The segue and delegate methods in the presenting view controller:

//MARK: -Navigation

@IBAction func addButtonTapped(_ sender: Any) {
    self.performSegue(withIdentifier: "addNewBusiness", sender: nil)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "addNewBusiness" {
        let destinationVC = segue.destination as! NewBusinessController
        destinationVC.delegate = self
    }
}

func businessAdded(data : JSON) {
    self.dismiss(animated: true, completion: nil) //Not working
    self.refresh(sender: self) //Working
    let text = data["message"].stringValue //Working
    print("My Businesses Controller: response JSON value is: \(text)") //Working
    self.alertDisplayer.showTopMessage(text: text) //Working
    self.soundPlayer.playSound(tone: "success") //Working
}

Solution

  • When dismissing a ViewController you should use the dismiss function, not a segue. For example:

    self.dismiss(animated: true, completion: nil)
    

    If it has been pushed in a UINavigationController, then you should instead pop it:

    self.navigationController?.popViewController(animated: true)