Hi, I'm using NSSplitViewController and once I load a viewcontroller with scrollview the IBActions of NSSwitch,NSButtons etc not work after I added the scrollview How can I fix it?
import Foundation
//Categories Protocal delegate
protocol CategoriesViewControllerDelegate: AnyObject {
func didSelectCategory(category: String)
}
class DetailViewController:NSViewController, NSOutlineViewDataSource, CategoriesViewControllerDelegate {
weak var delegate: CategoriesViewControllerDelegate?
override func viewDidLoad() {
// Other setup code...
detViewController = self
loadViewControllerWithScrollView(GeneralSettingsViewController.self, storyboardIdentifier: "GeneralSettingsViewController", originalViewController: self)
}
func didSelectCategory(category: String) {
// Handle the selected category in DetailViewController
print("Selected category: \(category)")
// Load the corresponding view controller or perform any other actions
switch category {
case "General":
// Load GeneralSettingsViewController
// Example: self.replaceCurrentViewController(with: GeneralSettingsViewController())
print("Load GeneralSettingsViewController")
loadViewControllerWithScrollView(GeneralSettingsViewController.self, storyboardIdentifier: "GeneralSettingsViewController", originalViewController: self)
case "DynaMusiX":
// Load DynaMusicSettingsViewController
// Example: self.replaceCurrentViewController(with: DynaMusicSettingsViewController())
print("Load DynaMusicSettingsViewController")
loadViewControllerWithScrollView(DynaMusicSettingsViewController.self, storyboardIdentifier: "DynaMusicSettingsViewController", originalViewController: self)
case "DynaGlance":
// Load DynaGlanceSettingsViewController
// Example: self.replaceCurrentViewController(with: DynaGlanceSettingsViewController())
print("Load DynaGlanceSettingsViewController")
loadViewControllerWithScrollView(DynaGlanceSettingsViewController.self, storyboardIdentifier: "DynaGlanceSettingsViewController", originalViewController: self)
default:
break
}
}
}
//Load viewcontroller with scrollview
func loadViewControllerWithScrollView<T: NSViewController>(_ viewControllerType: T.Type, storyboardIdentifier: String, originalViewController: NSViewController) {
let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: nil)
let newViewController = storyboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(storyboardIdentifier)) as! T
// Remove existing child view controllers
for childVC in originalViewController.children {
childVC.removeFromParent()
childVC.view.removeFromSuperview()
}
// Wrap the new view controller's view in a scroll view
let scrollView = NSScrollView()
scrollView.documentView = newViewController.view
scrollView.autoresizingMask = [.width, .height]
scrollView.hasVerticalScroller = true
scrollView.hasHorizontalScroller = false
scrollView.contentView.scroll(to: NSPoint(x: 0, y: newViewController.view.frame.height))
scrollView.translatesAutoresizingMaskIntoConstraints = true
// Set user interaction for the content view inside the scroll view
scrollView.documentView?.translatesAutoresizingMaskIntoConstraints = true
scrollView.documentView?.needsLayout = true
// Add the scroll view as a subview of the original view controller
originalViewController.view.addSubview(scrollView)
scrollView.frame = originalViewController.view.bounds
scrollView.layer?.zPosition = -1
}
t