2016-11-25 97 views
1

这是我的PopOver代码。我有两个视图控制器。我在消息传递视图控制器中呈现PopOver,并且需要管道的视图控制器是PreferencesView控制器。故事板ID也是相同的首选项视图控制器。 popOver是成功的,但总是覆盖整个屏幕。即使UIModalPresentationStyle.None。我在这里做错了什么?PopOver视图控制器覆盖全屏

func optionClicked(sender:UIBarButtonItem) 
{ 
    print(")show set preference and set reminder option") 


    let preferenceAction: UIAlertAction = UIAlertAction(title: "Set preferences", style: .Default) { action -> Void in 
     self.optionChoosed(true) 
     } 
    let reminderAction: UIAlertAction = UIAlertAction(title: "Set reminder", style: .Default) { action -> Void in 
     self.optionChoosed(false) 
    } 
    let actionSheetController: UIAlertController = UIAlertController(title: kAlertTitle, message: "What you want to do?", preferredStyle: .ActionSheet) 

    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in 
    } 
    actionSheetController.addAction(preferenceAction) 
    actionSheetController.addAction(reminderAction) 
    actionSheetController.addAction(cancelAction) 
    self.presentViewController(actionSheetController, animated: true, completion: nil) 
} 

func optionChoosed(isSetPreference:Bool) 
{ 


    if(isSetPreference) 
    { 
    print("Set preference") 

     let storyboard : UIStoryboard = UIStoryboard(name: "Messaging", bundle: nil) 
     let vc = storyboard.instantiateViewControllerWithIdentifier("PreferencesViewController") as! PreferencesViewController 
     vc.modalPresentationStyle = UIModalPresentationStyle.Popover 
     let popover: UIPopoverPresentationController = vc.popoverPresentationController! 
     popover.barButtonItem?.action = "isSetPreference" 
     popover.delegate = self 
     presentViewController(vc, animated: true, completion:nil) 


    } 

    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { 
     return UIModalPresentationStyle.None 

    } 
    func dismiss() { 
     self.dismissViewControllerAnimated(true, completion: nil) 
    } 
+0

其中从optionChoosed调用实现这个功能呢?当你点击栏按钮时会弹出PopOver? – Sahil

+0

是的,我有两个动作在酒吧按钮 – Niroj

+0

你可以显示完整的代码? – Sahil

回答

3

我猜你是从情节串连图板进行SEGUE。如果你这样做,从storyboard中移除segue,并为bar按钮项目创建一个动作,并将此代码放在那里。

let storyboard : UIStoryboard = UIStoryboard(name: "Messaging", bundle: nil) 
    let vc = storyboard.instantiateViewControllerWithIdentifier("PreferencesViewController") as! PreferencesViewController 
    vc.modalPresentationStyle = UIModalPresentationStyle.Popover 
    let popover: UIPopoverPresentationController = vc.popoverPresentationController! 
    vc.preferredContentSize = CGSize(width: 200, height: 200) 
    popover.barButtonItem = sender as? UIBarButtonItem 
    popover.delegate = self 
    presentViewController(vc, animated: true, completion:nil) 
+0

这里发件人是身份不明 – Niroj

+0

你必须通过它的功能。 self.optionChoosed(true,sender)和函数签名func optionChoosed(isSetPreference:Bool,sender:UIBarButtonItem) – Sahil

+0

yes!我检查了 – Sahil

0

尝试添加

vc.preferredContentSize = CGSize(width: 200, height: 200) 

我希望这将有助于

+0

我试过这不起作用 – Niroj

+0

你还可以添加popover.sourceView = base和popover.sourceRect = base.bounds – aahmetbas

+0

它说未解决的标识符基地 – Niroj

2

,你叫酥料饼

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