Modal View from UITabBarController

Like Instagram and other popular apps, I would like one of the buttons in my UITabBarController to present its view controller as a full-screen mode instead of a regular tab. I used Storiesboards to connect the UITabBarController to all of my child view controllers, and I cannot figure out how to present one view controller as modal. I found here a few other questions asking about the same thing, but they seem to assemble the tab bar manually, instead of using segues like me. Is this possible the way I do it?

+4
source share
2 answers

TL; DR - Check the code below.

I started with the axxixc approach, but ran into some problems. I tried to show the view using the method tabBarController:shouldSelectViewController: UITabBarControllerDelegate. However, iOS complained about a view already in the view hierarchy, which is obvious when you think about it, because the whole point of using UITabBarController in IB is that iOS processes instances of these views for us. So, I removed the parental look from him and stopped the mistakes, but the approach was still not felt so fragile. It also did not give me control over whether I wanted to re-create the view every time the model came out, which in my case I did.

, , IB, , . tabBarController:shouldSelectViewController: . , IB, , false .

:

func tabBarController(tabBarController: UITabBarController!, shouldSelectViewController viewController: UIViewController!) -> Bool {
    if viewController.title? == DUMMY_POST_VIEW_CONTROLLER_TITLE {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let actualController = storyboard.instantiateViewControllerWithIdentifier("ActualViewController") as ActualViewController
        presentViewController(actualController, animated: true, completion: nil)
        return false
    }

    return true
}
+9

, Instagram , UIKit, , UITabBarController UITabBarDelegate, -[UITabBarDelegate tabBar:didSelectItem:].

0

All Articles