Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating grouped table view

Can anyone let me know what the procedure is to create the grouped NSTableView similar to the Spotlight results.

enter image description here

like image 877
Suhaiyl Avatar asked May 30 '26 09:05

Suhaiyl


1 Answers

You probably won't get 100% there with the default behaviour provided by NSTableView, but pretty close.

For OS X v10.5 and up if you provide a NSTableViewDelegate (NSTableViewDelegate Protocol Reference) there's tableView:isGroupRow: you can provide.

Here's what it does for Default and Source List style table views on 10.6:
(setting the grouping flag for folders)

enter image description here

You can also provide tableView:heightOfRow: to adjust the row spacing and it get's pretty close (though with the group and content on different rows):

enter image description here

Other options that come to mind:

  • provide a custom NSCell with image and text plus styling, or
  • (for 10.7 and above) use an NSView based table view and an appropriate template

The TableViewPlayground example might offer a good starting point for the latter.

like image 144
Jay Avatar answered Jun 02 '26 20:06

Jay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!