是否可以在 Interface Builder 中创建一个具有预设行数的 NSTableView
,以便表格可以用作表单?
我有一个 View ,需要各种标签和文本字段的形式。我尝试过使用单个标签和文本字段,但看起来很差。与 NSForm
相同,它对布局和单元格内容附加了一些限制。
因此,表格 View 作为表单 View 看起来非常精致。我最想做的是将七个 TextTableViewCell
拖到 IB 中的静态 NSTableView
中,并在第一列中设置标签,并在第二列行中动态设置值。
但是如果我构建它,我的七行就会消失。如何让 NSTableView
保持静态?
最佳答案
正如 @Anc Ainu 指出的,从 OS X 10.10 开始,可以在 OS X 中使用静态 tableView。您必须将 NSTableView
上的 usesStaticContents
属性设置为使其表现得像 iOS 上的静态 tableView。根据文档:
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.
请记住,此属性在 OS X 10.10 及更高版本上可用。
关于macos - 带有预设行的静态 NSTableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30828815/