objective-c - 快速加载数据到 NSTableView

标签 objective-c macos swift nstableview appdelegate

我是 IOS/IOX 开发新手。我尝试了很多站点使用 NSTableView 将数据加载到我在 OSX swift 上的表中。但一切都失败了。 我做的程序是指 View-Based NSTableView in Swift - How to

  1. 拖放一个 NSTableView,当我运行代码时可以完美地看到它。
  2. 选择第一列并将列数设置为 1 后将标识符指定为“列表”
  3. 在我粘贴的 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
    
        }
    }
    
  4. 然后我尝试通过选择表并指向“应用程序场景”中的“App Delegate”,将委托(delegate)和数据源设置为 TableView 的 Appdelegate。但它没有链接

  5. 当我运行程序时,加载了没有单元格的表格

非常感谢任何帮助。

最佳答案

最简单的方法是在 XIB 文件中选择表格 View ,然后在右侧的“实用程序”面板中选择右数第三个图标(箭头指向右侧)。还要确保通过单击 Interface Builder 窗口左下方的图标来显示文档大纲。在实用程序面板中,您只需将委托(delegate)和数据源圈拖到文档大纲中的 AppDelegate。

关于objective-c - 快速加载数据到 NSTableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27397797/

相关文章:

ios - Obj-C - 删除自定义表格 View 单元格中按钮的表格 View 行被点击

objective-c - 如何打印出方法名称和行号并有条件地禁用 NSLog?

ios - 如何以编程方式快速切换到暗模式

swift - 如何在 Swift 的 while 循环条件下检查 `nil`?

iphone - 无法在 uiwebview 上双击缩放

objective-c - 高效地绘制数千个矩形并为其设置动画

macos - ionic :Error: Failed to fetch platform android in Mac?

python - 我可以在 Mac OS X 上的哪里保存 Python 开发的 GUI 应用程序的 sqlite 数据库?

objective-c - 每个 CPU 内核处于 C0 电源状态的时间

ios - 只需单击启动图标,应用程序就会卡住我的整个手机