Add child view controller to UITabBarController issue
Asked Answered
C

0

6

I'm trying to add an UIViewController as child view controller to the tab bar controller. See code below:

guard let vc = self.storyboard?.instantiateViewController(withIdentifier: "MyAlertViewController") as? MyAlertViewController else
{
    return
}

let base: UITabBarController = tabBarController!
base.addChildViewController(vc)
vc.view.frame = base.view.bounds
base.view.addSubview(vc.view)
vc.didMove(toParentViewController: base)

It works, but there is an issue that I'm unable to solve: MyAlertViewController is added to tab bar controller's viewControllers array, and sometimes it is even shown as a tab bar item. Is there a way to solve this? Thanks.

Centrality answered 7/5, 2019 at 7:29 Comment(1)
I believe this is a common issue. I have encountered issues adding children on navigation controller. It seems like native tools are cutting come corners and access children view controllers instead of persisting their own arrays. It is quite possible you will find no direct solution to this. You can add an extra view controller who's child is the navigation controller and then show alert on that view controller. In your case though I suggest you to create a new window (judging from context you want to show a custom alert view).Arleta

© 2022 - 2024 — McMap. All rights reserved.