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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30326680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 06:01:09  来源:igfitidea点击:

Added navigation bar but there is no back button?

iosuitableviewswiftsegueuistoryboardsegue

提问by sinusGob

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:

故事板的截图:

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

另一个截图,detailView 控制器没有后退按钮

enter image description here

在此处输入图片说明

采纳答案by gutenmorgenuhu

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

将 TableViewController 嵌入到 NavigationController 中。不是 DetailViewController 直接。查看屏幕截图。

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

确保连接 TableViewController 和 DetailViewController 的 segue 是Show (eg Push)类型。您必须在 Navigationstack 顶部真正推送一个新视图。

Check screenshot

检查截图

回答by OBEE

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

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

回答by Wallace Duncan

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.

单击 StoryBoardSegue,这是 tableviewcontroller 和 detailviewcontroller 之间的链接。在属性检查器中,即使选中了“动画”检查,您也可能需要单击它。在选择位于“种类”下拉菜单中的“显示(egPush)”后执行此操作。然后运行您的应用程序,然后在停止您的应用程序后重新选择相同的“动画”选项。我认为这是一个错误,我花了一个小时才弄清楚如何解决这个问题。此外,您可以使用已弃用的“推送”,但这将导致非法警告。已弃用的“推送”位于 StoryBoardSegue 属性检查器中的“种类”下。

回答by user155229

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.

我也在为此苦苦挣扎,我命名了 segue 的标识符,现在它可以工作了。只需从 Table View 中选择 Segue(箭头)到 View ,然后转到选项所在的右上角,然后选择 Show the attributes inspector。有一个标识符字段。

回答by Steven

Just make uinavigationwith UItableviewthen connect the Cell as ( show )

只需uinavigation使用UItableview然后将单元连接为(显示)

回答by Badr

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.

如果您当前的视图控制器嵌入在导航控制器中,则不需要将详细视图控制器嵌入导航控制器中。只需将一个按钮连接到详细视图控制器,返回导航就会自动出现。

回答by Amandeep

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

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