PopoverPresentationController

PopoverPresentationController

本文介绍了PopoverPresentationController变为nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在其中放置了一个按钮的情况下创建了SingleViewApplication.

Created a SingleViewApplication in that I have placed a button.

现在单击按钮,我需要将tableView显示为弹出窗口.TableViewController是在xib中创建的.

Now clicking on button I need to display a tableView as popover.The TableViewController is created in xib.

问题是tableViewController.popoverPresentationController始终为零,请参见下面的代码

The issue is tableViewController.popoverPresentationController always comes as nil see below code

     let filterVC =  TableViewController(nibName: "TableViewController", bundle: nil)
    var filterDistanceViewController = UINavigationController(rootViewController: filterVC)
    filterDistanceViewController.preferredContentSize = CGSize(width: 300, height: 200)
    let popoverPresentationViewController = filterDistanceViewController.popoverPresentationController
    popoverPresentationViewController?.permittedArrowDirections = .any


    if let pop = filterDistanceViewController.popoverPresentationController {
        pop.delegate = self
    }

上面的代码中的

filterDistanceViewController.popoverPresentationController始终为nil

in above codefilterDistanceViewController.popoverPresentationController is always coming as nil

任何正确方向的提示将不胜感激.

Any hint in right direction will be highly appreciated.

推荐答案

您什么都不显示,因此需要在当前的视图控制器上显示popoverPresentationViewController,例如:

You are not presenting anything, so you need to present the popoverPresentationViewController on the current viewcontroller, for example:

@IBAction func importantButtonPressed(_ sender: UIButton) {
         let tableViewController = UITableViewController()
         tableViewController.modalPresentationStyle = .popover

         present(tableViewController, animated: true, completion: nil)

        if let pop = tableViewController.popoverPresentationController {
          pop.delegate = self
        }

    }

这篇关于PopoverPresentationController变为nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 01:49