macos - 带有预设行的静态 NSTableView

标签 macos cocoa interface-builder nstableview

是否可以在 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/

相关文章:

xcode - 如何使用 OSX/XCode 构建 VST 插件

swift - NSCollectionViewItem 的圆角

objective-c - 如何在 Mac OS 10.5/10.6 中不使用 OpenSSL 解密河豚加密字符串

cocoa - 验证 Facebook token 时遇到问题

macos - 如何进行Mac App Beta测试和分发?

c++ - 从 Mac OS X 上的堆栈溢出中恢复

macos - OSX内置强制退出应用程序如何获取其应用程序列表?

ios - 从 NIB 加载自定义类 UIView (IBOutlets nil)

iphone - 如何从 XIB 文件加载 Storyboard ?

interface-builder - 在 Xcode 6 beta 5 中,将自动布局约束设置为占位符似乎不起作用?