0

I have a UITabBarController with 5 tabs. I want to be able to present a ViewController over all of the tabs, just above the Tab Bar. Currently the issue I am having is that when I present the ViewController modally, it is not visible. I have this function called whenever I select a row within a tableView:

The tableView where showPlayerView is called is defined like this:

class SearchResultsTableView: UIView, UITableViewDataSource, UITableViewDelegate

The class searchResultsTableView is a view inside of another class defined like this:

TestViewController: UIViewController, UserSearchDelegate, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate, UINavigationControllerDelegate

Here is the actual function:

func showPlayerView() {
    let playerView = PlayerView()
    playerView.modalPresentationStyle = .overCurrentContext
    CustomTabBarController.sharedInstance?.present(playerView, animated: true, completion: {

    })
}

and I set up the CustomTabBarController sharedInstance like this:

static var sharedInstance : CustomTabBarController?

and inside viewDidLoad() I have this:

CustomTabBarController.sharedInstance = self

Why can't I see my modal ViewController, and how can I get it to show on all screens?

1 Answers1

0
func showPlayerView() {
    let playerView = PlayerView()
    playerView.modalPresentationStyle = .overCurrentContext
    CustomTabBarController.sharedInstance?.tabBarController?.tabBar.hidden = true  // This will hide tab bar of your UITabbarViewController.
    CustomTabBarController.sharedInstance?.present(playerView, animated: true, completion: {

    })
}

// Make it visible in ViewWillApear method by below line

CustomTabBarController.sharedInstance?.tabBarController?.tabBar.hidden = false
Yagnesh Dobariya
  • 2,241
  • 19
  • 29
  • That didn't work. First of all, I can't call `self.present` because self refers to the UIView. When I changed `self.present` to `CustomTabBarController.sharedInstance?.present` to try and fix this, I got this error: `Warning: Attempt to present on whose view is not in the window hierarchy!` – Marshall Scudder Oct 30 '17 at 04:28
  • I have updated my answer. try again. May this help you. – Yagnesh Dobariya Oct 30 '17 at 04:50
  • present from TestViewController will remove the warning. you can set a call back to the TestViewController from your SearchResultsTableView – jpulikkottil Oct 30 '17 at 04:55
  • But then it won't appear on all of the 5 viewControllers in the UITabBar – Marshall Scudder Oct 30 '17 at 07:46