带有预设行的静态 NSTableView
Static NSTableView with preset rows
是否可以在 Interface Builder 中创建具有预设行数的 NSTableView
,以便 table 可以用作表单?
我有一个视图需要各种标签和文本字段的形式。我试过使用单个标签和文本字段,但看起来很差。与 NSForm
相同,它另外对布局和单元格内容施加了一些限制。
所以 table 视图作为表单视图看起来非常精致。我最想做的是将七个 TextTableViewCell
拖到 IB 中的静态 NSTableView
中,并在第一列中设置标签,并在第二列行中动态设置值。
但是如果我构建它,我的七行就消失了。我怎样才能让 NSTableView
保持静态?
正如@Anc Ainu 指出的那样,从 OS X 10.10 开始,可以在 OS X 中使用静态 tableView。您必须设置 usesStaticContents
属性 在 NSTableView
上使其表现得像 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 及更高版本。
是否可以在 Interface Builder 中创建具有预设行数的 NSTableView
,以便 table 可以用作表单?
我有一个视图需要各种标签和文本字段的形式。我试过使用单个标签和文本字段,但看起来很差。与 NSForm
相同,它另外对布局和单元格内容施加了一些限制。
所以 table 视图作为表单视图看起来非常精致。我最想做的是将七个 TextTableViewCell
拖到 IB 中的静态 NSTableView
中,并在第一列中设置标签,并在第二列行中动态设置值。
但是如果我构建它,我的七行就消失了。我怎样才能让 NSTableView
保持静态?
正如@Anc Ainu 指出的那样,从 OS X 10.10 开始,可以在 OS X 中使用静态 tableView。您必须设置 usesStaticContents
属性 在 NSTableView
上使其表现得像 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 及更高版本。