iosswiftuinavigationbarsegue

present UIViewController programatically


When I click on the newPostButton, I want to segue programmatically to the NewPostVC (which is that view on the right side). However, the view does not show up on the simulator, as you can see, it's completely black. What is the issue, why isn't the view showing up? And how to fix that? Thank you guys

FeedVC.swift Storyboard Simulator


Solution

  • If I understand correctly you are trying present view controller on your Navigation stack so you need to do two thing set storyborad ID and set push viewController here is code :

    Set 1:

    set Storyboard ID : NewPostVC to your NewPostVC Storyborad

    Step 2:

     @IBAction func newPostClicked(_ sender: UIButton) {
    
            let storyborad = UIStoryboard(name: "Main", bundle: nil)
    
            if let vc = storyborad.instantiateViewController(withIdentifier: "NewPostVC") as? NewPostVC {
                 self.navigationController?.pushViewController(vc, animated: true)
            }
    
        }