0

I am using UIPopoverPresentationControllerDelegate to show my popover, it's working fine but not able to manage width and height of the popover viewController. And how to set Presentation over current context ??

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let showObjectVC = storyboard?.instantiateViewController(withIdentifier: "ShowActorDetail") as! ShowActorDetailsViewController
    showObjectVC.modalPresentationStyle = .popover

    showObjectVC.popoverPresentationController?.sourceView = tableView.cellForRow(at: indexPath)
    showObjectVC.popoverPresentationController?.delegate = self
    showObjectVC.preferredContentSize = CGSize(width: 400, height: 300)

    present(showObjectVC, animated: true, completion: nil)
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
lpd
  • 165
  • 10

2 Answers2

0

instead of going with preferredContentSize try using the sourceRect property of UIPopoverPresentationController like,

showObjectVC.popoverPresentationController?.sourceRect = tableView.cellForRow(at: indexPath)!.frame

Make sure to point the frame of cell as you need in order for the popover to show at you desired position.

daris mathew
  • 429
  • 5
  • 18
-1

You can try another approach:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let showObjectVC = storyboard?.instantiateViewController(withIdentifier: "ShowActorDetail") as! ShowActorDetailsViewController
    // your logic
    presentViewControllerAsPopUp(showObjectVC)
}

private func presentViewControllerAsPopUp(_ vc: UIViewController) {
    vc.modalPresentationStyle = .overCurrentContext
    vc.modalTransitionStyle = .crossDissolve
    //self.definesPresentationContext = true
    self.present(vc, animated: true, completion: nil)
}

In ShowActorDetailsViewController you can make UIView with needed size and colored background.

Vitaly Potlov
  • 365
  • 1
  • 7
  • 14