简体   繁体   English

添加了导航栏但没有返回按钮?

[英]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我创建了一个表格视图,然后假设用户按下了一个单元格,它将转到 detailItemView ,但现在唯一的问题是,每当用户进入 detailItemView 时,即使我已经嵌入了导航控制器,也没有后退按钮

Here's the code that will perform a segue once a user pressed a cell:这是在用户按下单元格后将执行 segue 的代码:

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另一个截图,detailView 控制器没有后退按钮

在此处输入图片说明

Embed the TableViewController inside the NavigationController.将 TableViewController 嵌入到 NavigationController 中。 Not the DetailViewController directly.不是 DetailViewController 直接。 Check out the screenshot.查看屏幕截图。

Make sure, that the segue, connecting your TableViewController and your DetailViewController is of type Show (eg Push) .确保连接 TableViewController 和 DetailViewController 的 segue 是Show (eg Push)类型。 You have to literally push a new View on top of the Navigationstack.您必须在 Navigationstack 顶部真正推送一个新视图。

检查截图

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

Click on the StoryBoardSegue, the link between the tableviewcontroller and the detailviewcontroller.单击 StoryBoardSegue,这是 tableviewcontroller 和 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.在选择位于“种类”下拉菜单中的“显示(egPush)”后执行此操作。 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.已弃用的“推送”位于 StoryBoardSegue 属性检查器中的“种类”下。

I was struggling with this also, and I named the Identifier of the segue, and now it works.我也在为此苦苦挣扎,我命名了 segue 的标识符,现在它可以工作了。 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.只需从 Table View 中选择 Segue(箭头)到 View ,然后转到选项所在的右上角,然后选择 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”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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