"Dismiss" does not work

Hey there,


I have the following problem:

I created a view named "View Controller" with a Segue to "Über View Controller".

Now in "Über View Controller" I have a bar button item with the system item "Cancel". From this item I created an Action to "UeberViewController.swift".

Source code of the file is the following:


import UIKit

class UeberViewController: UIViewController {
    @IBAction func Done(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
}


Now the problem:

The dismiss-action does not work. If I tap on the button nothing happens...


Anyone an idea what to do?

Accepted Reply

Now it works.

I have had no class for Ueber View Controller and so I could implement an Action which works.


However, thanks for advice.

Replies

Have you checked

- you have effectively connected the Done button to the IBAction ?

- that this func is called (insert a print("Done") to check


If you just want to dismiss, there is another way to achieve this, without the IBAction:

- ncreate an unwindAction in ViewController

- connect the button to the exit of the ViewController (at the top of its window) and select the unwind action.

Hi Claude,

thanks for your reply.

Seems there is a problem with the connection because there is no "Done" on the console.

Also the unwindAction does not work. I must push the control-key to connect, that's true? In this case it is not possible to drag a line to "Exit".


I implemented a similar "Cancel"-Action in another view and it works. But there are options to connect an Outlet, Action or Outlet Collection. In the other view I can just connect an Action and the Object is fixed "Exit" (in other View it is "Game Controller" and I can change it).


All Attributes of the two Navigation Bars are equal.


I have no idea what to do now.

Just because you tried to help me with this issue: View the full discussion

I think you don't see any way to fix it (because of misssing reply)?

When you got the Done button, was it for a view embedded in a navigation controller.


You can:

- embed View Controller in a navigation controller

- then the back button should work

Note: you can also do what I proposed to connect to exit

Now I embed the View Controller in a Navigation Controller. But this change nothing at all.

I'm only able to connect a Action with "Exit" like I wrote above.


Note: you can also do what I proposed to connect to exit

How does this work? I found this article so I implemented a function

@IBAction func unwindToViewController(segue: UIStoryboardSegue) {
        print("Done")
    }

to UeberViewController.swift.

Now I can control-drag to "Exit" but it doesn't work at all! Same behaviour like before.

Now it works.

I have had no class for Ueber View Controller and so I could implement an Action which works.


However, thanks for advice.