Home > front end >  How can I create and use a table in Xcode 10.1?
How can I create and use a table in Xcode 10.1?

Time:01-11

I am trying to create and use an NSTableView object, but trying to connect it gives me NSScrollView instead of NSTableView, I need to know how to insert, delete, and refresh the table.

I am not using a storyboard project and am far too into development to switch. Can someone help with this? I am using Xcode 10.1

CodePudding user response:

When you drag a “table view” into a XIB (or storyboard), Xcode inserts a scroll view with several subviews:

  • NSScrollView
    • NSClipView
      • NSTableView
    • NSScroller (vertical)
    • NSScroller (horizontal)
    • NSTableHeaderView

Here are two ways to make connections with the NSTableView. (There are other ways, but I think these two are the easiest.)

Document Outline

The XIB editor is a split view. The main area of the XIB editor, on the right, is the canvas pane where it shows your views laid out graphically. On the left is the document outline pane.

The document outline has two modes: icon mode and outline view mode. You want to show the outline view. One way to toggle between the modes is to click the button at the bottom left of the canvas pane. The button looks like this:

document outline show/hide button

Another way is to choose Editor > Document Outline from the menu bar. You can make the outline view wider (and the canvas narrower) by dragging the vertical separator line between the two panes.

After you have shown the document outline view, turn down the outline disclosure triangles as needed to show the scroll view, the clip view, and the table view in the outline:

document outline view with window, content view, scroll view, and clip view children disclosed

Now you can connect directly to or from the table view in the document outline.

View Hierarchy Pop-Up Menu

Another way to access the table view is with a shift-control-click or shift-right-click over it in the canvas pane. That means you hold the shift key and the control key down on your keyboard while you click your mouse button over the table view (or you hold the shift key while clicking your right mouse button). In response, Xcode shows a pop-up menu of all objects under the mouse pointer:

view hierarchy pop-up menu

From this menu, you can select the table view. Once the table view is selected, you can control-click (or right-click) and drag from the table view to another object to establish a connection.

  • Related