0

I want to use a push segue to edit an "entry" that is otherwise added via a present modally segue. It doesn't dismiss using the normal dismissViewControllerAnimated method when pressing cancel. Because of this I had to combine the popViewControllerAnimated method at the same time, so that depending on whether they click cancel when editing an entry or adding it, it will try both.

Both are done via NSNotifcation, because of objects I need to carry back from the last viewcontroller to the first:

func cancel(notification: NSNotification){
    println("Cancel Executed")
    let userInfo:Dictionary<String,EntryItem!> = notification.userInfo as Dictionary<String,EntryItem!>
    entry = userInfo["Object"]
    tableView.reloadData()
    self.navigationController?.popViewControllerAnimated(true)
    dismissViewControllerAnimated(true, completion: nil)
    dataModel.saveEntries()

}

The problem with this is that if I go through the segues to arrive at the third view controller (in a string of 5), I cancel, and it goes back to the entries screen, but a messed up looking navigation bar takes the place of what is supposed to be there. There's no title showing either. It has a cancel button which causes a crash if you press it.

Here's what it's supposed to look like:

enter image description here

Here's what the popViewControllerAnimated does to it.

enter image description here

Nathan McKaskle
  • 2,926
  • 12
  • 55
  • 93
  • You could check if the UIViewController is presented modally. Then, decide how to remove the UIViewController. (func presentedModally() -> BOOL { return self.presentingViewController.presentedViewController == self || self.navigationController.presentingViewController.presentedViewController == self.navigationController – Jonathan Dec 29 '14 at 01:04
  • I will try that. What comes after that dash at the end there? self.navigationController - ...? – Nathan McKaskle Dec 29 '14 at 21:02
  • No such luck, it doesn't seem to work. It's returning false even if it's true. Not sure how self.navigationController.presentingViewController.presentedViewController == self.navigationController would return a value that indicates whether it's presented modally. Even if it did work, popViewControllerAnimated still messes up the bar regardless of whether the other dismissViewController is called. – Nathan McKaskle Dec 29 '14 at 21:12

0 Answers0