Search code examples
swiftuiviewcontrollersegueuistoryboarduistoryboardsegue

Swift - Permanent View Controller Segue (outside of Navigation Controller)


Having some trouble permanently moving one from view controller to another. The normal segues seem to all have a 'go back' option.

I know I can imbed the VC in a navigation controller and create a custom segue which rewrites the hierarchy/changes root VC

class ReplaceSegue: UIStoryboardSegue {

    override func perform() {
        source.navigationController?.setViewControllers([self.destination], animated: false)
    }
}

But I want to avoid a navigation controller as it will confuse things when I add a SWRevealViewController later.

Can/Should I change the storyboard VC (outside of AppDelegate that is)?

Thanks - apologies if this is a 'beginner' question


Solution

  • You can either change rootViewController of your main window:

    self.window.rootViewController = vc
    

    or you can just simply set vc's modalPresentationStyle to fullscreen (this doesn't have a "go back" option by itself, only you can dismiss it calling dismiss)

    
    let vc = UIViewController()
    vc.modalPresentationStyle = .fullScreen
    

    or from storyboard change it's presentation style to fullscreen.