简体   繁体   English

如何从嵌入在不同UINavigationControllers中的多个UIViewController转到一个UIViewController

[英]How do I segue to one UIViewController from multiple UIViewControllers embedded in different UINavigationControllers

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. 另一种是选择一种电梯类型,用于按电梯类型过滤用户电梯的日志。

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: 当您点击UITableViewCell转到选择提升屏幕时,视图会按预期从右向左滑动, 但是 ,它会立即从右向左再次滑动视图,导航栏将指向其自身:

在此输入图像描述

Here's my storyboard layout: 这是我的故事板布局:

在此输入图像描述

Here's the relevant segue code: 这是相关的segue代码:

// 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

    }
  }

I'm using Swift 2.3 and Xcode 8. 我正在使用Swift 2.3和Xcode 8。

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. 我已经阅读了Apple的文档,并在SO上发现了几个涉及多个vc进入一个vc的主题,但他们要么处理传递数据问题或其他事情。

Can anybody tell me why this is happening and how to fix it? 任何人都可以告诉我为什么会发生这种情况以及如何解决这个问题?

UPDATE : 更新

Made the change suggested by @vacaWama and now it appears from the bottom and with no navigation bar: 做了@vacaWama建议的更改,现在它从底部显示,没有导航栏:

在此输入图像描述

UPDATE 2: 更新2:

.storyboard source code exceeded the limit so here's a link to it on GitHub: .storyboard源代码超出了限制所以这里是GitHub上的链接:

Link to storyboard file 链接到故事板文件

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 . 我怀疑你从原型单元连接你的segue,所以当你选择单元格时会触发它,第二次调用performSegueWithIdentifier时会触发它。 If you want to call the segue programmatically, wire it from the viewController icon at the top of your tableViewController. 如果要以编程方式调用segue,请从tableViewController顶部的viewController图标中进行连接。

@vacawama, you suspect correctly. @vacawama,你怀疑是正确的。 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. 我尝试将segue连接到它嵌入的导航控制器,但这并没有什么区别。 Do you know how I can fix this? 你知道我怎么解决这个问题吗?

You need to select the segue arrow in the storyboard, and then change the kind of segue in the Attributes Inspector to Show . 您需要在故事板中选择segue箭头,然后在Attributes Inspector中将segue的类型更改为Show

If I use a Show segue directly to Select a lift type , it pushes from right to left. 如果我直接使用Show segue Select a lift type ,它会从右向左推动。 If I use a Show segue to the Navigation controller , it presents modally. 如果我使用Show segue到Navigation controller ,它会以模态方式呈现。 Rewire your segue and make sure it is going directly to the viewController and not the Navigation controller . 重新连接你的segue并确保它直接进入viewController而不是Navigation controller

暂无
暂无

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

相关问题 如何从UINavigationController选择到UIViewController - How do I segue from a UINavigationController to a UIViewController 一个UIViewController可以连接到不同的多个UIViewControllers吗? - Can a UIViewController connect to different multiple UIViewControllers? Swift UIViewController到另一个UIViewControllers(segue) - Swift UIViewController to another UIViewControllers (segue) 在来自第三个UIViewController的两个UIViewController之间执行搜索 - Perform a segue between two UIViewControllers from third UIViewController 是否可以在屏幕上不显示两个NavigationBar的情况下将两个不同的UINavigationControllers锁定到同一UIViewController? - Can two different UINavigationControllers segue to the same UIViewController without having two NavigationBars appear on screen? 6个单独的UIViewControllers还是仅一个具有不同数据源的对象决定在segue进行? - 6 separate UIViewControllers or just one with different data sources decided at segue? 如何将UIButton附加到源自其他UIViewController的segue? - How to attach a UIButton to a segue originating from a different UIViewController? 如何以编程方式从一个UIViewController切换到另一个,而无需模态或Push? - How to programmatic segue from one UIViewController to another without Modal or Push? 如何在添加其他视图时从视图中删除UIViewController? - How do I remove a UIViewController from the view while adding a different one? 当不在UIViewController中时,如何触发segue显示特定视图? - How do I trigger a segue to show a specific view, when not in a UIViewController?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM