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

时间:2017-01-18 08:42:44

标签: ios swift uitabbarcontroller uipopovercontroller

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

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)

  }

它不起作用,有什么帮助?

1 个答案:

答案 0 :(得分:1)

更改以下行:

showLanguagePopOver(UIView)

这一行:

showLanguagePopOver(self.view)