0

I have an NSAlert and I set its accessoryView to be an NSTableView. It works good with small-medium amounts of data, but when the row count is getting large, the tableview resizes instead of getting a scrollbar. I would expect the table to only take up as much space as I give it in the Init frame.

 var alert = NSAlert()
 var sampleTable = NSTableView(frame: NSRect(x: 0, y:0, width: 400, height:400))
 sampleTable.dataSource = self
 alert.accessoryView = sampleTable
 alert.beginSheetModal(...) // irrelevant code from here on
Salman Ghumsani
  • 3,647
  • 2
  • 21
  • 34
Edged
  • 29
  • 5
  • You need to enclose the NSTableView inside an NSScrollView. – Eric Aya Nov 27 '17 at 13:16
  • That partially solves it. However, now anything outside of the NSScrollView is hidden as the NSTableView does not show a scrollbar and doesn't allow trackpad scrolling. – Edged Nov 27 '17 at 13:52
  • Is this still an alert or just a dialog? – Willeke Nov 27 '17 at 17:41
  • OK, that helped. I am able to scroll through it using mousewheel/touchpad, but unfortunately, no scrolling bar appears. Is it possible to make it show up? And it's an Alert with the accessoryview set to be a table for the user to deselect items from. Guess I am repurposing it to be a dialog. But I haven't found a dialog class by itself in Cocoa. – Edged Nov 27 '17 at 18:58
  • A dialog is a viewcontroller or window presented as a sheet or run modal. – Willeke Nov 28 '17 at 00:16

1 Answers1

0

Set the scrolliew.autohidesScrollers = false and scrollView.hasHorizontalScroller = true where scrollView is an NSScrollView instance

Sentry.co
  • 5,355
  • 43
  • 38