Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static NSTableView with preset rows

Is it possible to create a NSTableView in Interface Builder that has a preset number of rows so that the table can be used as a form?

I have a view that requires a form of various labels and textfields. I've tried using single labels and textfields but it looks poor. Same with the NSForm which additional put a couple of restrictions on layout and cell content.

So a table view looks very polished as a form view. What I would optimally like to do is drag seven TextTableViewCells into a static NSTableView in IB and set labels in the first column and dynamically set values in the second column rows.

But if I build it my seven rows disappeared. How can I get an NSTableView to act static?

like image 344
BadmintonCat Avatar asked Jun 14 '15 11:06

BadmintonCat


1 Answers

As @Anc Ainu pointed out, as of OS X 10.10 it is possible to use static tableViews in OS X. You have to set the usesStaticContents property on NSTableView to make it behave like a static tableView on iOS. According to the docs:

A static table does not rely on a data source to provide the number of rows. A static table view’s contents are set at design time and can be changed programmatically as needed. Typically, you do not change the contents of a static table view after setting them.

In Xcode, any rows you add to a static table are saved in the corresponding nib or storyboard file and loaded with the rest of the table at runtime. You can add table rows programmatically to a static table view using the insertRowsAtIndexes:withAnimation: method. When adding rows programmatically, your table view delegate must implement the tableView:viewForTableColumn:row: method to provide the corresponding view for any new rows. You can also remove rows at any time using the removeRowsAtIndexes:withAnimation: method.

Please remember that this property is one available on OS X 10.10 and later.

like image 116
mangerlahn Avatar answered Nov 03 '22 08:11

mangerlahn