隐藏模态视图控制器而不解除(更改位置)

时间:2017-07-13 07:08:28

标签: ios

我在模态控制器中有一些任务,我需要在打开另一个对象时,只更换控制器中的某些元素。我找到了以下示例In iOS, how to drag down to dismiss a modal?,一切正常,但我需要确保当我关闭我的控制器时隐藏并且不触发事件deinit。我想有两个事件:解雇和隐藏。

1 个答案:

答案 0 :(得分:1)

你应该做的是保留viewController的内存引用。

例如:

// Load all CSS files in the current directory and descendants
const context = require.context('!raw-loader!./', true, /\.css$/);
const cssFiles = {};

for (let filename of context.keys()) {
  cssFiles[filename] = context(filename);
}

只要您的ParentViewController生效class ParentViewController: UIViewController { // place this here to keep it in ParentViewController's memory var subViewController: SubViewController? override func viewDidLoad() { super.viewDidLoad() // initialize the subViewController and set it as the attribute self.subViewController = SubViewController() } func showSub() { if let unwrappedSubViewController = self.subViewController { self.present(unwrappedSubViewController, animated: true, completion: nil) } } func dismissSub() { self.subViewController?.dismiss(animated: true, completion: nil) } } class SubViewController: UIViewController { .. some properties here } 的内存引用,就不会被删除/取消分配

如果您想完全删除引用,请执行此操作。

subViewController