0
votes

Ok, I have an issue that I cant understand trying to present a view controller (the same instance every time, just like other tab item VCs) from an overall tab bar controller VC. My tab bar controller VC has 3 view controllers that it is connected to via storyboard, so 3 tab bar items appear on the tab bar. When the selectedIndex is changed, these view controllers just appear right there below the subviews of the Tab Bar Controller VC.

These subviews that should always be on top are the nav bar at the top and tab bar at bottom:

enter image description here

And this is great for those 3 view controllers. Problem is I need to access 1 instance of ANOTHER view controller that is NOT shown in the tab bar buttons via a button in the nav bar here.

My problem is no matter how I present it, this VC always pops OVER the tab bar controller VC, covering the tab bar and nav bar.

here I make sure only 1 instance is made:

if podcastVC == nil {
            //print("IT IS NIL")
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            podcastVC = storyboard.instantiateViewController(withIdentifier: "podcast") as! PodcastViewController

            //*NOTE: have to set other vars too, this is temp
            podcastVC.urlStr = currentTrackUrl!
            podcastVC.originalUrl = currentTrackUrl!
            AudioPlayerManager.shared.play(urlString: podcastVC.urlStr)
        }

        self.show(podcastVC, sender: self)
        podcastVC.modalPresentationStyle = .currentContext
        podcastVC.definesPresentationContext = false


  [1]: https://i.stack.imgur.com/1d6MZ.png

as shown by Swift: How to return to the same instance of my UIViewController

How can I make that VC present in the same context as the tab bar items? I have tried setting the layer of the nav bar to a z position much higher (like 10) but nothing works. What is wrong?

1
Presented ViewController covers the whole screen.Mannopson
ok right. So how can I show it in the same context NOT covering the screen?skyguy
Are you tried to use the show instead of present. It's just worksMannopson
what are you talking about look above I am using show and it presents it right over everythingskyguy
Oops! From my understanding, you'd like to present instantiated ViewController from your TabBarController's viewControllers, right?Mannopson

1 Answers

0
votes

Modal view : Can works for all view controllers Is over all other view and need to be pop programatically (adding a button back manually for example)

Push View : Only works in navigation controllers Add automatically a back button in the navigationController

you should push VC and it will keep tabbar and nav you can change modal present style