我是 IOS/IOX 开发新手。我尝试了很多站点使用 NSTableView 将数据加载到我在 OSX swift 上的表中。但一切都失败了。 我做的程序是指 View-Based NSTableView in Swift - How to
- 拖放一个 NSTableView,当我运行代码时可以完美地看到它。
- 选择第一列并将列数设置为 1 后将标识符指定为“列表”
在我粘贴的 appdelegate.swift 中
class AppDelegate: NSObject, NSApplicationDelegate,NSTableViewDataSource,NSTableViewDelegate { func applicationDidFinishLaunching(aNotification: NSNotification?) { } func applicationWillTerminate(aNotification: NSNotification?) { } func numberOfRowsInTableView(aTableView: NSTableView!) -> Int { println("reached 1") return 10 } func tableView(tableView: NSTableView, viewForTableColumn: NSTableColumn, row: Int) -> NSView { println("reached 2") var cell = tableView.makeViewWithIdentifier("List", owner: self) as NSTableCellView cell.textField.stringValue = "Hey, this is a cell" return cell } }
然后我尝试通过选择表并指向“应用程序场景”中的“App Delegate”,将委托(delegate)和数据源设置为 TableView 的 Appdelegate。但它没有链接
- 当我运行程序时,加载了没有单元格的表格
非常感谢任何帮助。
最佳答案
最简单的方法是在 XIB 文件中选择表格 View ,然后在右侧的“实用程序”面板中选择右数第三个图标(箭头指向右侧)。还要确保通过单击 Interface Builder 窗口左下方的图标来显示文档大纲。在实用程序面板中,您只需将委托(delegate)和数据源圈拖到文档大纲中的 AppDelegate。
关于objective-c - 快速加载数据到 NSTableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27397797/