heisenberg heisenberg - 29 days ago 5
Swift Question

Let UIView scene disappear when navigation bar item tapped

I made an IBAction for my "Done" navigation bar button. When the button is tapped I would like to let it disappear/dismiss and switch back to previous scene.

@IBAction func doneButton(sender: AnyObject) // action for "Done" button in navigation bar
{
if tabBarController?.selectedIndex == 0
{
optionExpirationInput.text = calculatedDifferenceInDays // difference in days is being applied to the input field

// date picker scene should disappear and switch back to Option Input Scene?? but nothing happens
self.dismissViewControllerAnimated(true, completion: nil)

}
else if tabBarController?.selectedIndex == 1
{
volatilityExpirationInput.text = calculatedDifferenceInDays

// date picker scene should disappear and switch back to Volatility Input Scene?? but nothing happens
self.dismissViewControllerAnimated(true, completion: nil)

}
}


My attempts to do this failed. I would greatly appreciate if you could help me.

Answer

replace this line

self.dismissViewControllerAnimated(true, completion: nil)

with this

self.navigationController?.popViewController(animated: true)
Comments