My root view controller is a UITabBarController. I\'m trying to present a modal view controller over one of the tab bar controller\'s view controllers, but still allow the
I have same problem in currently live swift project. I have did workaround on that.
Then finally i have used NSNotificationCenter
and dismiss that view controller when tab is changed to solve this problem.
I have referenced tabbar controller in AppDelegate
and set delegate there.
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let tabbarcontroller = storyboard.instantiateViewControllerWithIdentifier("MyTabBarController") as! UITabBarController
tabbarcontroller.delegate = self
And it's delegate as
//MARK: - Tabbar controller delegate
extension AppDelegate : UITabBarControllerDelegate {
func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
NSNotificationCenter.defaultCenter().postNotificationName("TabBarTabChanged", object: nil)
}
}
Then I have add observer in my presented view controller as
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(PreviewPlaceVC.BackClickAction(_:)), name: "TabBarTabChanged", object: nil)
}
// MARK: - Button Click Actions
@IBAction func BackClickAction(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
And it's work fine for me. Not a proper solution I think to dismiss view controller on tab change event, but it is ok to dismiss rather than black screen which also breaks navigation that time.