简体   繁体   中英

Added navigation bar but there is no back button?

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:

在此处输入图片说明

edited Screenshot

在此处输入图片说明

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

在此处输入图片说明

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 (eg Push) . You have to literally push a new View on top of the Navigationstack.

检查截图

我刚才遇到了同样的问题,通过删除 segue、再次添加并立即给它一个标识符来解决。

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(egPush)" 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.

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.

只需使用uinavigation进行UItableview然后将 Cell 连接为 ( show )

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.

在属性检查器中将 detailView 的“Interface style”更改为“Inferred”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM