14
votes

I created a table view and from there let say a user pressed a cell it will go to the detailItemView , but the only problem right now is that whenever a user is in detailItemView there is no back button even thought I already embed a navigation Controller

Here's the code that will perform a segue once a user pressed a cell:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    // Get the new view controller using [segue destinationViewController].
    var nav = segue.destinationViewController as! UINavigationController
    var detailScene = nav.topViewController as! DetailViewController


    // Pass the selected object to the destination view controller.
    if let indexPath = self.tableView.indexPathForSelectedRow() {
        let row = Int(indexPath.row)
        detailScene.currentObject = objects?[row] as? PFObject
    }
}

The screenshot for the storyboard:

enter image description here

edited Screenshot

enter image description here

I tried to do the answer below but there is still no back button

Another screenshot, the detailView controller doesn't have a back button

enter image description here

7
BackButton are only use to go to previous ViewController which is on the same NavigationController (stack). So since your new ViewController is the only one with a NavigationController according to your image...Larme
Can i use it to to go back to UITableView?, could you show some answer so I could accept itsinusGob
The NavigationController needs to be before the TableViewController like gutenmorgenuhu's answer.Rasputin

7 Answers

14
votes

Embed the TableViewController inside the NavigationController. Not the DetailViewController directly. Check out the screenshot.

Make sure, that the segue, connecting your TableViewController and your DetailViewController is of type Show (e.g. Push). You have to literally push a new View on top of the Navigationstack.

Check screenshot

3
votes

I've had the same issue just now, resolved by deleting segue, adding again and giving it an identifier straight away.

3
votes

Click on the StoryBoardSegue, the link between the tableviewcontroller and the detailviewcontroller. In the attributes inspector you may need to click on the "Animates" check even if it is checked. Do this after selecting "Show(e.g.Push)" located in the "Kind" drop down menu. Then run your app and then reselect the same "Animates" option after stopping your app. I think this is a bug and it took my an hour to figure out how to solve this. Additionally, you can use the deprecated "Push" but this will illicit a warning. Deprecated "Push" is under "Kind" in the StoryBoardSegue attributes inspector.

1
votes

I was struggling with this also, and I named the Identifier of the segue, and now it works. Just select the segue (the arrow) from the Table View to the View , then go to the right top side, where the options are, and select Show the attributes inspector. There is a field for the Identifier.

0
votes

Just make uinavigation with UItableview then connect the Cell as ( show )

0
votes

If your current view controller is embedded in a navigation controller, you don't need to embed the detail view controller in a navigation controller. Just connect a button to the detail view controller and the back navigation will come automatically.

0
votes

change "Interface style" to "Inferred" of detailView in Attributes inspector