Xcode 12拆分视图控制器的意外行为?

问题描述

在使用Xcode 12和IB的简单macOS测试应用程序中,我具有以下代码。它具有一个拆分视图窗口,唯一的代码是下面的代码。我构建它是为了学习如何允许用户更改窗口的背景色。此代码在单个Window / View Controller中可以正常工作。但是,当我在拆分的Window / View Controller中尝试相同的代码时,不会调用操作代码(changeColor)。是否有人知道这种情况以及如何使此代码与分屏控制器一起工作?

class ViewController: NSViewController {

    let colorPanel = NSColorWell()
    

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.wantsLayer = true
        self.view.layer?.backgroundColor = NSColor.gray.cgColor
        // Do any additional setup after loading the view.
    }
    @IBAction func changeBKColor(_ sender: NSButton) {
        colorPanel.activate(true)
        colorPanel.action = #selector(changeColor)
    }

    @objc func changeColor(_ sender: NSButton?) {
        print("Layer is",self.view.layer!)
          self.view.layer?.backgroundColor =  colorPanel.color.cgColor
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)