0

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?

blue
  • 7,175
  • 16
  • 81
  • 179
  • Presented `ViewController` covers the whole screen. – Mannopson Jul 13 '17 at 00:55
  • ok right. So how can I show it in the same context NOT covering the screen? – blue Jul 13 '17 at 00:56
  • Are you tried to use the `show` instead of `present`. It's just works – Mannopson Jul 13 '17 at 01:03
  • what are you talking about look above I am using show and it presents it right over everything – blue Jul 13 '17 at 01:23
  • Oops! From my understanding, you'd like to present instantiated `ViewController` from your `TabBarController`'s `viewControllers`, right? – Mannopson Jul 13 '17 at 01:55
  • If I'm understanding you, yes. I need the new, presented podcastVC to live right alongside the tabbarControllers view controllers. under the nav bar and tab bar with them – blue Jul 13 '17 at 02:34

1 Answers1

0

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

tai do
  • 124
  • 6
  • Is there a way to push without a back button? I have tried to remove it in past and it did not work – blue Jul 13 '17 at 12:04