swiftxcodemacosnssplitviewnstabview

Making Inspector Sidebar in macOS Window


I would like to make an "inspector sidebar" in a macOS window. You know the inspector in Xcode:

Xcode inspector

The sidebar's content should be context sensitive. Depending on the user's selection in the main window there should be different dialogs.

Which technologies do I have to use to get this behavior?

My attempts were (in Storyboard):

  1. Insert a Split View into the window.
  2. Insert a Tab View Controller into the right Custom View of the Split View

But this didn't worked: I could easily insert the Split View into the window. And I could easily insert a Tab View Controller to the Storyboard. But I was not able to insert the Tab View Controller into the right view of the Split View.

So how do I achieve the desired behavior?


Solution

  • Finally I solved the issue. I had to add a CustomView to each of the tab's CustomViews. This way, Xcode added ViewControllers automatically. Here are the individual steps:

    First, I had to insert a SplitView into the storyboard. Nothing problematic here yet.

    SplitView

    Second, I've added a TabView (Style: tabless) into one of the CustomViews:

    SplitView with TabView

    And third, I needed to add ContainerViews to each of the tabs:

    SplitView with TabViews with ContainerViews

    This way Xcode added ViewControllers for each of the tab's ContainerViews:

    enter image description here

    No I can chose the different Tabs programmatically:

    @IBAction func showInspector1(_ sender: NSButton) {
        self.tabView.selectTabViewItem(at: 0)
    }
    @IBAction func showInspector2(_ sender: NSButton) {
        self.tabView.selectTabViewItem(at: 1)
    }
    

    I would like to thank for the comments, that helped me making progress and solving this issue.