popViewController does not go back

I am making an app that is retrieving images from parse and showing it to a collection view. When the user taps on the images the image show in detail. I have a textfield that the user can change. When the user changes something they hit the save button and goes back to the collection view. The code that goes back to the collection view controller does not work.

  @IBAction func saveButton(sender: AnyObject) {

    // Use the sent country object or create a new country PFObject
    if let saveInBackWithBlock = currentObject as PFObject? {
        updateObject = currentObject! as PFObject
    } else {
        updateObject = PFObject(className:"Tops")
    }

    // Update the object
    if let updateObject = updateObject {

        updateObject["imageText"] = topsLabel.text

        // Create a string of text that is used by search capabilites
        var searchText = (topsLabel.text)
        updateObject["searchText"] = searchText

        // Update the record ACL such that the new record is only visible to the current user
        updateObject.ACL = PFACL(user: PFUser.currentUser()!)

        // Save the data back to the server in a background task
        updateObject.saveInBackgroundWithBlock{
            (success: Bool, error: NSError?) -> Void in
            if (success) {
                // The object has been saved.

            } else {
                // There was a problem, check error.description
            }
        }

        print("saved")

    }
   self.navigationController?.popViewControllerAnimated(true)

        }

I don't know why it doesn't go back to the previous view controller.Thank you

Answers


Is your parent view embedded in a navigation controller? also - how has the view been presented?

From the post you just added - you cannot pop a modal VC - try dismissing the view controller instead.


Check if it's embed in Navigation Controller, try:

  1. Click StroryBoard
  2. Select first viewController
  3. Click Editor -> Embed in -> Navigation Controller

Hope it helps.


Need Your Help

Drag and Drop portlets in websphere portal 8

websphere websphere-portal drag-and-drop

Anybody has experience dragging and dropping the portlets in websphere portal 8 standard layout. I am able to drag and drop in the static page but the standard page doesn't allow it. Any suggestion...

Assigning rows to variables using MySQLi and PHP

php mysqli

I'm just starting to dab into MySQLi after using MySQL for a while. I found this little code snippet on a tutorial, and just had a question about it (since Google won't return any results for me on...