7

I am using xcode 6. I have a 'Cancel' button in my storyboard, when I click it, I want to dismiss my view controller and go back to where I come from. So in my storyboard, I wire the cancel button to my View Controller with 'Touch up' to my 'handleCancel' method.

When I touch the button, I see 'handleCancel' is being called. I see the debug printfs I put it. But it does not dismiss my current view controller.

@IBAction func handleCancel(sender: AnyObject) {      
    println("Calling handle Cancel")
    self.dismissViewControllerAnimated(false, completion: nil)
}

Can you please tell me what else I am missing?

Thank you.

hap497
  • 154,439
  • 43
  • 83
  • 99

1 Answers1

14

What is the current controller class? UIViewController? UINavigationController? Etc. What was the class of the presenting controller? Finally, what kind of segue did you use? Check the connections inspector in storyboard if unsure. There will be different techniques based on these answers.

For example, if this is a push segue in a UINavigationController you would pop the view with:

self.navigationController?.popViewControllerAnimated(true)

Any ways, let us know.

Steve Rosenberg
  • 19,348
  • 7
  • 46
  • 53
  • The current controller is a UIViewController. It has a 'cancel' button. I want to dismiss it when user presses the 'cancel' button. Before that the controller was a UITableViewController and I launched this controller by clicking a button in the navigation bar. I use 'show' segue in the button. – hap497 Sep 22 '14 at 00:52
  • Is it a push segue or a modal segue? – Steve Rosenberg Sep 22 '14 at 01:34
  • WOW you seriously solved the problem I had! Thanks for the explanation and answer. I had different types of Controllers, I didn't realize you had to use different methods to dismiss. – Pangu Feb 21 '16 at 07:51