Unexpected behavior with Xcode 12 split view Controller?

I have the following code in a simple macOS test app using Xcode 12 and IB. It has one split view window and the only code is the code below. I built it to learn how to allow a user to change background colors for a window. This code works fine in a single Window/View Controller. However, when I try the same code in a split Window/View Controller the action code (changeColor) does not get called. Does any body know way this is the case as well as how to get this code working with a split screen controller.

Code Block
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

}
A split view has multiple view controllers: one for the split view and one for each split view item. My guess is one of the other view controllers is getting the message to change the background color. Which view controller has the button that triggers the IBAction?

If you want the whole window's background color to change, you should put the IBAction to change the color in the split view controller. Then you can go through each child view controller and change the view's background color.
Thanks for the reply.

I have tried putting the IBAction to change the color in both of the children view controller with the same results. I was trying to change the right side of the split view. Based on your reply I created a sub class for the Parent Controller and used my code above in it. But I was not able to connect the IBAction to a button in the Parent Controller. So, I don't think I quite understand your reply?

I wish I could simply upload my test project and you could take a look at it to see what I am talking about. However, in lieu of that, If you have time or anyone else you could create my test project by the following.
  1. Using Xcode 12 create a new macOS project called ColorSetting

  2. Add a Window Controller with a side bar.

  3. In either of the child views or both create a custom NSViewController

  4. Copy and paste the code above in the custom Class

  5. add a button in a view and connect it to the IBAction in the custom class

At any rate I will continue to investigate this issue.

Never mind I see how it works. I have to be the change color function in my custom split view controller.

Thanks
Unexpected behavior with Xcode 12 split view Controller?
 
 
Q