How to click a new view without a Swift storyboard

First of all, I do not want to use storyboards at all. I can β€œsubmit” the target view controller, but I cannot get it to show the standard iOS back button at the top. My understanding is that I can make this work by clicking on the controller instead of presenting it. I get no errors, but nothing happens.

When a button is pressed, this code starts. The commented code is what is successfully presented in the ForgotPasswordPage file:

// Changes to the forgotten password page

func forgotPasswordSwitch(sender: UIButton!) { //let ForgotPassword:ForgotPasswordPage = ForgotPasswordPage() //self.presentViewController(ForgotPassword, animated: true, completion: nil) let ForgotPassword = ForgotPasswordPage() self.navigationController?.pushViewController(ForgotPassword, animated: true) } 
+5
source share
2 answers

You need to manually create a UINavigationcontroller to get a back panel. For this, you can use the code of this answer , which achieves this, using this code:

 self.window = UIWindow(frame: UIScreen.mainScreen().bounds) var nav1 = UINavigationController() var mainView = ViewController() //ViewController = Name of your controller nav1.viewControllers = [mainView] self.window!.rootViewController = nav1 self.window?.makeKeyAndVisible() 

Here, simply add all the ViewControllers that you want to be under the navigation controller to the array, and then click between them.

Hope this helps, Julian

+2
source

I know that sometimes it develops applications much better programmatically, but there are many times when Storyboard can save you a lot of time. You just use it for this situation ...

1) In your storyboard, localize the view controller that you want to enable for clicking

2) Select it and find "Editor" in the top panel

3) Select "Editor-> Paste In-> Navigation Controller

And now your view controller is ready to click

0
source

Source: https://habr.com/ru/post/1239534/


All Articles