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:
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.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 theNavigation controller
, it presents modally. Rewire your segue and make sure it is going directly to theviewController
and not theNavigation controller
.