2015-04-23 39 views
1

我在UITabBarCOntroller上創建按鈕並嘗試調用應用程序中所有屏幕上的模態視圖。我嘗試使用WYPopoverController作爲解決 我的UITabBarController類是UITabBarController上的WYPopoverController屬於

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它錯誤

**類星球的實例0x7fe4a48849d0墜毀。當關鍵值觀察者仍然註冊時,AddPlanController被解除分配。現有的觀測信息:( 語境:爲0x0,物業:0x7fe4a4915e00> **

請給我一個建議如何調用像從按鈕UITabBar模態視圖控制器,這將是在所有屏幕,陰影BG。 =(

回答

0

你必須保持參考popoverController直到它的可見的,但現在,當你從showAddPlan方法返回釋放。

popoverController移動定義從功能,它會工作