macOS模式新窗口,在其contentView的viewDidLoad之后调用windowController的windowDidLoad吗?

时间:2019-02-08 19:36:13

标签: swift macos nsviewcontroller nswindowcontroller

我有一个使用情节提要的macos App,在情节提要中有两个窗口。

如果我单击第一个窗口上的按钮,它将对第二个窗口模态化,但是我发现新窗口的contentView首先被加载,然后是窗口加载。怎么可能呢?

代码如下:

import pandas as pd
import numpy as np

i = ['dog', 'cat', 'elephant'] * 3
df = pd.DataFrame(np.random.randn(9, 4), index=i, 
columns=list('ABCD')).sort_index()

代码:

+-----------+      +------------+
|           |      |            |
|  Window A |      | Window B   |
|           |      |            |
+-----+-----+      +-----+------+
      v                  v
+-----+-----+      +-----+-------
| View A    |      | View B     |
|           |      |            |
| buttonA   |      | property   |
+-----------+      +------------+


在文件中:

  @IBAction func buttonA(_ sender: Any) {

    let storyboard = NSStoryboard(name: "Main", bundle: nil)
    let windowBWC = storyboard.instantiateController(withIdentifier: "Window B Controller") as! WindowBWindowController

    let viewBVC = windowBWC.contentViewController as! ViewBViewController

    // set viewBVC property


    let application = NSApplication.shared
    guard let window = viewBVC.view.window else { return }
    application.runModal(for: window)

    window.close()
  }
// WindowBWindowController.swift

class WindowBWindowController: NSWindowController {

    override func windowDidLoad() {
        super.windowDidLoad()

        // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.

      print("windowDidLoad")
    }
}

当我单击按钮时,将显示该视图,但是我首先有viewDidLoad,然后是windowDidLoad,这对我来说很直观,应该先有一个窗口,然后再有一个视图。

0 个答案:

没有答案