显示模态视图并在视图中更新变量

时间:2018-08-10 09:18:07

标签: swift view modal-dialog optional

我有一个视图,试图像弹出窗口一样显示,并且前一个视图在后台可见。

我已经尝试过了:

let popupView = PopupViewController.init(nibName: "PopupView", bundle: nil)

    popupView.modalPresentationStyle = .overCurrentContext
    present(popupView,animated: true,completion: nil)

这会显示模态罚款,这是当我想动态更新视图中的标签时遇到的问题,因为视图尚未完全初始化,从而导致:

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

使用:

    let popupView = PopupViewController.init(nibName: "PopupView", bundle: nil)
    popupView.textLabel.text = "Hello World"
    popupView.modalPresentationStyle = .overCurrentContext
    present(popupView,animated: true,completion: nil)

使用modalPresentationStyle可以使我在模态视图中动态更改值的正确方法是什么?

0 个答案:

没有答案