Swift 2中的segue没有返回按钮

7

我刚刚将我的项目迁移到Swift 2,一切都运行得很好——除了最简单的Segue没有后退按钮。这是我正在使用的准备Segue函数:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if segue.identifier == "showExercise" {
        if let nav = segue.destinationViewController as? UINavigationController {
            if let exercisesController = nav.topViewController as? ExercisesController {
                let cell = sender as! WorkoutCell
                if let workout = cell.name!.text {
                    exercisesController.exercises = Workouts[workout]!
                    exercisesController.navigationItem.title = workout
                }
            }
        }
    }
}

以前,返回按钮会自动填充到父视图的过渡。现在,我只能得到子导航VC中的标题。

1个回答

10

你是使用show或show detail segue吗?看起来你正在使用模态segue。对于显示或显示segue的目标视图控制器通常是第二个视图控制器本身,而不是嵌入在另一个 UINavigationController 中。

如果您的show segue的目标视图控制器确实是UINavigationController,则新导航控制器的导航栏设置可能会覆盖旧的(源视图控制器的导航控制器)。试着不要将您的目标视图控制器嵌入到另一个 UINavigationController 中。


那似乎就是问题所在!将 segue.destinationViewController 从它自己的 UINavigationController 中移除即可解决。干杯!顺便说一下,我正在使用 Show (e.g. Push) - cadlac
@cadlac,你可以把可行的代码作为答案发布吗?我不明白你的修复如何在不破坏其他代码的情况下起作用。 - Ryan Pierce

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接