0

I am trying to get a popover working in swift.

The view i am trying to put into the popover is in its own separate xib.

The code to load is below

    let view = OrganisationDetails()
    view.modalPresentationStyle = .Popover
    let popoverMenuViewController = view.popoverPresentationController
    view.preferredContentSize =  CGSizeMake(550,550)
    popoverMenuViewController?.permittedArrowDirections = .Any
    popoverMenuViewController?.delegate = self
    popoverMenuViewController?.sourceView = sender
    popoverMenuViewController?.sourceRect = CGRect(x: 1, y: 1, width: 60, height: 60)
    presentViewController(view, animated: true, completion: nil)

What is happening atm is the popover is loading totally blank and not displaying the view.

Any ideas what I'm doing wrong

Thanks

2 Answers 2

2

Actually it is much simpler than that. In the storyboard you should make the viewcontroller you want to use as popover and make a viewcontroller class for it as usual. Make a segue as shown below from the object you want to open the popover, in this case the UIBarButton named "Config".

enter image description here

In the "mother viewcontroller" implement the "UIPopoverPresentationControllerDelegate" and the delegate method:

func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
    //do som stuff from the popover
}

Override the "prepareForSeque" method like this:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
     //segue for the popover configuration window
    if segue.identifier == "yourSegueIdentifierForPopOver" {
        if let controller = segue.destinationViewController as? UIViewController {
            controller.popoverPresentationController!.delegate = self
            controller.preferredContentSize = CGSize(width: 320, height: 186)
        }
    }
}

And your done. And you can now treat the popover view as any other view, ie. add fields and what not!

Sign up to request clarification or add additional context in comments.

Comments

0

This is how I do it

    //MARK:idPopupFileTable
    let popoverVC = storyboard?.instantiateViewControllerWithIdentifier("idPopupFileTable") as UIViewController
    popoverVC.modalPresentationStyle = .Popover
    popoverVC.preferredContentSize = CGSizeMake(300, 200)

    if let popoverController = popoverVC.popoverPresentationController {
      popoverController.sourceView = sender
      popoverController.sourceRect = sender.bounds
      popoverController.permittedArrowDirections = .Any

      popoverController.delegate = self
    }
    presentViewController(popoverVC, animated: true, completion: nil)

  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.