0

the thing is im new to ios development this is my second application while working on the first one i mainly used a theme and then worked over it but this one im working from scratch.

My main problem is going from one screen to another

When i use this code it works

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
        let nextViewController = storyBoard.instantiateViewController(withIdentifier: "servicesScreen") as! ServiceViewController
        nextViewController.modalPresentationStyle = .fullScreen
        self.present(nextViewController, animated:true, completion:nil)
   

But i need to use this one so i can go back too but this wont do anything

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let newViewController = storyBoard.instantiateViewController(withIdentifier: "servicesScreen") as! ServiceViewController
        self.navigationController?.pushViewController(newViewController, animated: true)

My question is, am i doing anything wrong here or do i need to add something in scenedeligate?

Maroof Int
  • 13
  • 3

2 Answers2

0

try

select Main.storyboard

select initial view Controller

select editor -> Embed in -> navigation controller.

Sagar Bhut
  • 657
  • 6
  • 28
0

For this, you need to add navigation controller to initial storyboards.

If you are using navigationController you need to add a navigation controller first on storyboard or programmatically.

Programmatically add navigation controller check this link:-

Creating a navigationController programmatically (Swift)

or

To add navigation controller on storyboard you should follow this link:- https://developer.apple.com/library/archive/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ImplementNavigation.html

If you have added navigation controller to your app then make sure your intialViewController is set to navigation controller or your navigation controller is added to the stack when you run your application.

Also check for "Is the identifier correct? Did you reference the correct storyboard?".

Apps Maven
  • 1,314
  • 1
  • 4
  • 17
  • thankyou but embedding navigation controller to my main screen worked had to hide navigation bar though on the controller – Maroof Int Aug 05 '20 at 06:48