首页 > 解决方案 > 将 UIViewController 呈现为弹出框

问题描述

我将我的应用程序设置为NewHelpRequestViewController通过单击数组中的最后一个单元格来连接到另一个。我想要做的是将视图控制器作为弹出窗口打开。

class MainViewController : UITableViewController, UIPopoverPresentationControllerDelegate {


override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
    if indexPath.row == questionViewCellArray.count-1 {
        self.performSegue(withIdentifier: "showNewRequest" , sender : self)
    }
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showNewRequest" {
        if let controller = segue.destination as? NewHelpRequestViewController {
            controller.popoverPresentationController!.delegate = self
            controller.preferredContentSize = CGSize(width: 200, height: 300)
        }
    }
}

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

现在它将打开NewHelpRequestViewController,没有任何问题或错误。我链接了我可以链接的相关代码。如果我需要展示其他内容,请告诉我。

我还应该提到这是针对 iPhone 的。

标签: iosswiftpopover

解决方案


推荐阅读