0

I have tabbarController where i put parent viewController with container view inside.

public override func viewDidLoad() {
    viewControllers = [
         ParentViewController()
    ]
}

On init i'm initializing 2 child view controllers and adding 1st controller (that does't contain MapView) as child viewController. At some point of time i need to switch between child controllers, and in that point app crashes

public class ParentViewController: UIViewController {

    @IBOutlet weak var containerView: UIView! 

    let firstChildController: ViewControllerWithoutMapView
    let secondChildController: ViewControllerWithMapView

    init() {
        firstChildController = ViewControllerWithoutMapView()
        secondChildController = ViewControllerWithMapView()
        super.init(nibName: "ParentViewController", bundle: nil)
    }

    public override func viewDidLoad() {
        firstChildController.view.frame = containerView.bounds
        addChildViewController(firstChildController)
        firstChildController.willMoveToParentViewController(nil)
        containerView.addSubview(firstChildController.view)
        firstChildController.didMoveToParentViewController(self)
    }

    func switchChildControllers() {
        secondChildController.view.frame = containerView.bounds <<<<< crash here
        .....
    }
}

I know about crashes that appears if you're not importing MapKit, i tried to import it everywhere - no luck.

What is the correct way to switch child viewControllers with MapView inside one of it?

CrimeZone
  • 230
  • 2
  • 13

0 Answers0