1
votes

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:

enter image description here

Here's my storyboard layout:

enter image description here

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:

enter image description here

UPDATE 2:

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

Link to storyboard file

1
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
Is there is segue connected from the settings->Lifts screen to the 'select lift type' screen? Does the 'Lifts' cell gets highlighted when you click on segue in the storyboard? And I second what @vacawama said. - Bista
@vacawama, you suspect correctly. Thanks for pointing out my rookie mistake. However, 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? - Jim
You need to select the segue arrow in the storyboard, and then change the kind of segue in the Attributes Inspector. - vacawama
Sorry, I should have mentioned that I tried changing the segue type. I've tried both Show (e.g. Push) and Show Detail (e.g. Replace) and both result in the same behavior. Since this is the behavior I want if I come from the log screen, it makes me think the nav controller this Select a Lift view is embedded in is forcing the segue to be modal but at the same time not presenting it with the nav bar. - Jim

1 Answers

0
votes

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.