0
votes

I am trying to create segues between my UIViewControllers but am having some difficulties with creating a segue from a UITableViewCell and a UIButton.

When I create a show detail segue through storyboard from a UITableViewCell to a UIViewController it works perfectly and I get the back button showing up. But when I try to create a show detail segue from a UIButton to a UIViewController it doesn't register the navigation stack and presents the screen modally without the back button.

How can I make a successful show detail segue from a UIButton to a viewcontroller? I am new to iOS and am having trouble determining why the UIButton segue doesn't behave the same as the UITableViewCell segue.

Thanks in advance for any help!

2

2 Answers

0
votes

Dont connect a segue manually do it through button action.

This is assuming the viewController that has this button is the root view controller of the navigation controller

 @IBAction func myButtonTapped(_ sender: Any) {
    let vc = self.storyboard!.instantiateViewController(withIdentifier: "YOUR STORYBOARD IDENTIFIER GOE HERE")
    self.show(vc, sender: self)
 }

If you want to go to a tab of a tab bar controller you have to specify its index. I think you can set it in storyboard but i just go with 0 is on the left then they go up sequentially. so in the example below i want to go to the second tab of the tab bar controller with a modal transition. I assume you can use show here like example above I've just never done it.

    let tbc = self.storyboard!.instantiateViewController(withIdentifier: "MyTabController") as! UITabBarController
        tbc.selectedIndex = 1  // this is 2nd tab index.. start at 0
        tbc.modalPresentationStyle = .overCurrentContext
        tbc.modalTransitionStyle = .coverVertical
        self.present(tbc, animated: true, completion: { finished in
            // you can also do some completion stuff in here if you require it.
            // self.view.removeFromSuperview()
            // self.navigationController?.navigationBar.removeFromSuperview()

        })
0
votes
let vc = self.storyboard!.instantiateViewController(withIdentifier: "StoryBoardID")
self.navigationController?.pushViewController(vc, animated: true)