我在UITabBarCOntroller上创建按钮,并尝试在应用程序的所有屏幕上调用模态视图。我尝试使用WYPopoverController作为解决方案
我的UITabBarController类是

class PlanetTabBarController: UITabBarController, WYPopoverControllerDelegate {

override func viewDidLoad() {
    super.viewDidLoad()
    self.tabBar.tintColor = kTintColor

    var items = self.tabBar.items as! [UITabBarItem]
    let centredTabBar:UITabBarItem = items[2]
    self.tabBar.layer.borderWidth = 0.50

    centredTabBar.image = UIImage()
    self.tabBar.layer.borderColor = UIColor.clearColor().CGColor
    self.tabBar.layer.borderWidth = 0

    self.tabBar.shadowImage = UIImage()
   // self.tabBar.backgroundImage = ktabBarImage
    self.tabBar.backgroundImage?.imageWithAlignmentRectInsets

    print( UIDevice.currentDevice().modelName)
    if( UIDevice.currentDevice().modelName != "iPhone 6" && UIDevice.currentDevice().modelName != "iPhone 6 Plus"){
       self.tabBar.backgroundImage = ktabBarImage
    }
    if( UIDevice.currentDevice().modelName == "iPad 2" ){
        self.tabBar.backgroundImage = ktabBarImage
    }



        if let font = UIFont(name: "Avenir-Black", size: 10) {
            let appearance = UITabBarItem.appearance()
            let attributes = [NSFontAttributeName:font]
            appearance.setTitleTextAttributes(attributes, forState: UIControlState.Normal)

        }


    let buttonImage:UIImage = UIImage(named: "tab_planet")!

    var button: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
    button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height)
    button.setBackgroundImage(buttonImage, forState: UIControlState.Normal)

    var heightDifference:CGFloat = buttonImage.size.height - self.tabBar.frame.size.height
    if (heightDifference < 0){
        button.center = self.tabBar.center
        button.center.y = self.tabBar.center.y - 5
    }else{
        var center:CGPoint = self.tabBar.center
        center.y = center.y - heightDifference/2.0 - 5
        button.center = center
    }
    button.addTarget(self, action: "addPlanet:", forControlEvents: .TouchUpInside)
    self.view.addSubview(button)






}

func addPlanet(sender: UIButton!) {
    self.showAddPlan()
}

func showAddPlan(){

    var contentViewController =  UIStoryboard(name: "AddPlan", bundle: nil).instantiateViewControllerWithIdentifier("AddPlanController") as? AddPlanController


    var popoverController = WYPopoverController(contentViewController: contentViewController)
    popoverController.delegate = self

    popoverController.presentPopoverFromRect(CGRectZero, inView: nil, permittedArrowDirections: WYPopoverArrowDirection.None, animated: false) { () -> Void in
        print ("done")
    }






}

func popoverControllerShouldDismissPopover(popoverController: WYPopoverController!) -> Bool {
    return false
}

}
但是当我试图调用我的AddPlanController时,它出错了
**Planet.AddPlanController类的实例0x7fe4a48849d0被释放,而键值观察器仍在其中注册。当前观察信息:(
上下文:0x0,属性:0x7fe4a4915e00>
**
请告诉我如何调用uitabar上按钮中的modal view controller,这将覆盖所有屏幕,并带有shadow bg。=(

最佳答案

您必须保留对popoverController的引用,直到它可见为止,但现在当您从showAddPlan方法返回时,它被释放。
popoverController的定义从您的函数中移除,它将起作用

关于ios - UITabBarController上的WYPopoverController下降,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29827887/

10-09 16:29