如何从嵌入在不同 UINavigationControllers 中的多个 UIViewControllers 转到一个 UIViewController [英] How do I segue to one UIViewController from multiple UIViewControllers embedded in different UINavigationControllers

查看:20
本文介绍了如何从嵌入在不同 UINavigationControllers 中的多个 UIViewControllers 转到一个 UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的举重应用程序中,我有一个视图控制器,我想将其用于几个不同的目的.一种是选择将保存为用户默认值的电梯类型.另一种是选择一种电梯类型,用于按电梯类型过滤用户的电梯日志.

In my weightlifting app, I have a view controller that I want to use for a couple of different purposes. One is to select a lift type that will be saved as the user's default. The other is to select a lift type that will be used to filter a log of the user's lifts by lift type.

其中一个路径(选择默认值)从设置屏幕开始.当您点击 UITableViewCell 转到 Select a Lift 屏幕时,视图按预期从右向左滑入,然而,它立即将视图再次从右向左滑入,导航栏指向回到,好吧,它本身:

One of the paths (choosing a default) starts at a Settings screen. When you tap the UITableViewCell to go to the Select a Lift screen, the view slides in from right to left as expected, however, it immediately slides the view in again from right to left and the navigation bar points back to, well, itself:

这是我的故事板布局:

这是相关的转场代码:

// MARK: - Segues

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "goToLifts" {
            let vc = segue.destinationViewController as! LiftSelectionTableViewController
            vc.delegate = self
        } else {
            return
        }
    }

  override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath) {
    switch indexPath.row {
    case 0: performSegueWithIdentifier("goToFormulas", sender: self)
    break
    case 1: performSegueWithIdentifier("goToLifts", sender: self)
    break
    default:
      break

    }
  }

我使用的是 Swift 2.3 和 Xcode 8.

I'm using Swift 2.3 and Xcode 8.

我已经阅读了 Apple 的文档并发现了几个关于 SO 的主题,这些主题涉及多个 vc 转到一个 vc,但它们要么处理传递数据问题,要么处理其他问题.

I've read Apple's documentation and found several topics on SO that involve multiple vc's going to one vc but they're either dealing with passing data problems or other things.

谁能告诉我为什么会发生这种情况以及如何解决?

Can anybody tell me why this is happening and how to fix it?

更新:

进行@vacaWama 建议的更改,现在它从底部显示并且没有导航栏:

Made the change suggested by @vacaWama and now it appears from the bottom and with no navigation bar:

更新 2:

.storyboard 源代码超出限制,因此这是 GitHub 上的链接:

.storyboard source code exceeded the limit so here's a link to it on GitHub:

链接到故事板文件

推荐答案

我怀疑你是从原型单元格连接了你的 segue,所以当你选择单元格和第二次调用 performSegueWithIdentifier<时它会被触发/代码>.如果您想以编程方式调用 segue,请从 tableViewController 顶部的 viewController 图标连接它.

I suspect you wired your segue from the prototype cell, so it is getting triggered when you select the cell and a second time when you call performSegueWithIdentifier. If you want to call the segue programmatically, wire it from the viewController icon at the top of your tableViewController.

@vacawama,你猜对了.该视图现在以模态呈现并且没有导航栏(请参阅我的编辑的问题).从设置屏幕,我希望它从从右到左,但从日志屏幕我确实希望它以模态呈现从底部.我尝试将 segue 连接到导航控制器它是嵌入的,但这并没有什么不同.你知道我怎么可以解决这个问题吗?

@vacawama, you suspect correctly. The view is now presenting modally and with no navigation bar (see my edited question). From the Settings screen, I want it to slide in from right to left, but from the log screen I DO want it to present modally from the bottom. I tried connecting the segue to the nav controller it's embedded in, but that didn't make a difference. Do you know how I can fix this?

您需要在 storyboard 中选择 segue 箭头,然后在 Attributes Inspector 中将 segue 的种类更改为 Show.

You need to select the segue arrow in the storyboard, and then change the kind of segue in the Attributes Inspector to Show.

如果我直接使用 Show segue 来选择电梯类型,它会从右向左推动.如果我对 Navigation controller 使用 Show segue,它会以模态方式呈现.重新连接你的 segue 并确保它直接进入 viewController 而不是 Navigation controller.

If I use a Show segue directly to Select a lift type, it pushes from right to left. If I use a Show segue to the Navigation controller, it presents modally. Rewire your segue and make sure it is going directly to the viewController and not the Navigation controller.

这篇关于如何从嵌入在不同 UINavigationControllers 中的多个 UIViewControllers 转到一个 UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆