简体   繁体   中英

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:

在此输入图像描述

Here's my storyboard layout:

在此输入图像描述

Here's the relevant segue code:

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

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?

UPDATE :

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

在此输入图像描述

UPDATE 2:

.storyboard source code exceeded the limit so here's a link to it on 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 . If you want to call the segue programmatically, wire it from the viewController icon at the top of your tableViewController.

@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?

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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