(<UIPopoverPresentationController: 0x7fdb10687050>) 应该在演示发生之前设置一个非零的 sourceView 或 barButtonItem。

(<UIPopoverPresentationController: 0x7fdb10687050>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'

我在标签栏控制器中创建了一个导航项按钮。

class TabBarContoller: UITabBarController,UIPopoverPresentationControllerDelegate {
 ...
        let languageBtn = UIBarButtonItem(title: "EN", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(Language))
      // navigationItem.rightBarButtonItem = [rightButton , languageBtn]
        navigationItem.setRightBarButtonItems([rightButton,languageBtn], animated: true)

我想运行这个函数当它选中这个按钮时,它会弹出一个视图控制器:

 func showLanguagePopOver(base: UIView)  {
        let popOverContent = self.storyboard?.instantiateViewControllerWithIdentifier("Languages")as! Languages
        popOverContent.preferredContentSize = CGSizeMake(150, 150)
        let nav = UINavigationController(rootViewController: popOverContent)
        nav.modalPresentationStyle = .Popover
        let popOver = nav.popoverPresentationController
        popOver?.delegate = self
        popOver?.sourceView = base
        popOver?.sourceRect = base.bounds
        popOver?.sourceRect = CGRect(x: 0, y: 0, width: 100, height: 25)
        self.presentViewController(nav, animated: true, completion: nil)
    }

我试着这样称呼它:

func Language()
{
  showLanguagePopOver(UIView)

  }

没用,有什么帮助吗?

更改以下行:

showLanguagePopOver(UIView)

这一行:

showLanguagePopOver(self.view)