Q:

How to present popover from tab bar item?

I want to present a ViewController as popover in Swift 4, but it presents the Viewcontroller normally, this is the code:
class CustomTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let favViewController = TrialViewController()
        let exhibtionViewController = TrialViewController()
        let menuViewController = ttttViewController()
        let notificationViewController = TrialViewController()
        let profileViewController = ttttViewController()

        favViewController.tabBarItem.title = "first"
        exhibtionViewController.tabBarItem.title = "second"
        menuViewController.tabBarItem.title = "third"
        notificationViewController.tabBarItem.title = "forth"
        profileViewController.tabBarItem.title = "fifth"

        favViewController.tabBarItem.image = UIImage(named:"home25")
        exhibtionViewController.tabBarItem.image = UIImage(named: "bag25")
        menuViewController.tabBarItem.image = UIImage(named: "main_add_25")
        notificationViewController.tabBarItem.image = UIImage(named: "notification25")
        profileViewController.tabBarItem.image = UIImage(named: "man_man25")

        let tabBarItemWidth = Int(self.tabBar.frame.size.width) / (self.tabBar.items?.count)!
        let x = tabBarItemWidth * 3;
        let newRect = CGRect(x: x, y: 0, width: tabBarItemWidth, height: Int(self.tabBar.frame.size.height))
        print(newRect)

        menuViewController.modalPresentationStyle = .popover
        menuViewController.view.frame = newRect
        menuViewController.preferredContentSize = CGSize(width: 150,height: 150)

        if let popoverMenuViewController = menuViewController.popoverPresentationController {
            popoverMenuViewController.permittedArrowDirections = .down
            popoverMenuViewController.delegate = menuViewController as? UIPopoverPresentationControllerDelegate
            popoverMenuViewController.sourceRect = newRect
            popoverMenuViewController.sourceView = self.tabBar

            present(menuViewController, animated: true, completion: nil)

        }

        viewControllers = [favViewController, exhibtionViewController, menuViewController, notificationViewController, profileViewController]
    }

}

what is the problem with my code?

A:

override func viewDidAppear(_ animated: Bool) {

    let vc = self.storyboard?.instantiateViewController(withIdentifier: "bbb") as! ttttViewController
    vc.modalPresentationStyle = .popover //presentation style

    vc.preferredContentSize = CGSize(width: 150,height: 150)
    vc.popoverPresentationController?.delegate = self as! UIPopoverPresentationControllerDelegate
    vc.popoverPresentationController?.sourceView = view
    vc.popoverPresentationController?.sourceRect = self.tabBar.frame
    self.present(vc, animated: true, completion: nil)

}

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return  .none
}

demo is here popover 

