【发布时间】:2017-05-19 21:25:31
【问题描述】:
这是我的 PopOver 代码。我有两个视图控制器。我在 Messaging View 控制器中展示 PopOver,需要通过管道传输的视图控制器是 PreferencesView 控制器。 Storyboard Id 也是相同的 Preferences View 控制器。 popOver 是成功的,但总是覆盖全屏。即使 UIModalPresentationStyle.None。我在这里做错了什么?
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)
}
【问题讨论】:
-
从哪里调用 optionChoosed ?并在您单击栏按钮时显示 PopOver?
-
是的,我在栏按钮中有两个操作
-
你能显示完整的代码吗?
-
我应该发布什么代码
-
我的意思是从哪里调用 optionChosed?显示调用 optionChoosed 的代码。