skip to Main Content

This is the first one, normal with no problems
This is the first one, normal with no problems

There’s an extra layer for everytime i go to a new view.
There's an extra layer for everytime i go to a new view

you could see it increases each time
you could see it increases each time

Whenever i go to a different view on xcode there’s a layer that’s the size of a toolbar that’s blocking my view, i’m new to swift so I’m sorry if i don’t use the proper terms but can anyone please help me with this issue?

this is the code that i use to switch views

    let register = UIStoryboard(name: "RegisterEmail", bundle: nil)
    let controller =register.instantiateViewController(identifier:"RegisterEmail") as! RegisterEmail 
    let navigation = UINavigationController(rootViewController:controller)
    self.view.addSubview(navigation.view)
    self.addChild(navigation)
    navigation.didMove(toParent: self)

edit(solved the problem) but

let storyboard = UIStoryboard(name: "ForgotPassword", bundle: nil)
    let secondViewController = storyboard.instantiateViewController(withIdentifier: "ForgotPassword") as! ForgotPassword
    self.navigationController?.pushViewController(secondViewController, animated: true)

doesn’t work, any help?

2

Answers


  1. It looks like your are adding a new navigation stack inside the current navigation stack, this should be why you have new navigation bar inside the view. You should only push or show the view.

    Login or Signup to reply.
  2. Like the previous answer says, you keep adding a UINavigationController view to the view of your viewController. I believe you already added a UINavigationController to your storyboard, therefore, to grab it, just use self.navigationController. You don’t need to create a new one and add it to the viewStack. It is already presenting your current VC.
    I can’t understand what you want to achieve. If you want each view to have its own VC, then the code in the second code snippet should work – if you created three viewController in the storyboard. However, from the first code snippet, it looks like you want to add three child viewController. If this is the case, change the code snippet to

    let storyboard = UIStoryboard(name: "ForgotPassword", bundle: nil)
    let childVC = storyboard.instantiateViewController(withIdentifier: "ForgotPassword") as! ForgotPassword
    addChild(childVC) 
    childVC.view.frame = frame
    view.addSubview(childVC.view)
    childVC.didMove(toParent: self)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search