四列NSTableView的RubyCocoa控件方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了四列NSTableView的RubyCocoa控件方法相关的知识,希望对你有一定的参考价值。

  1. # What you NEED in the controller to be able to list someting in a NSTableView in RubyCocoa
  2. #
  3. # Creates the storage array, and another array which contains the names of the columns.
  4. def initialize
  5. @objects = Array.new
  6. @columns = ["Column Name 1", "Column Name 2", "Column Name 3", "Column Name 4"]
  7. end
  8.  
  9. # Returns the numbers of rows in the array for NSTableView to display.
  10. def numberOfRowsInTableView(aTableView)
  11. return @objects.length
  12. end
  13.  
  14. # Uses the @columns array to to enable a flexible number of columns when fetching data.
  15. def tableView_objectValueForTableColumn_row(afileTable, aTableColumn, rowIndex)
  16. @columns.each do |column|
  17. if aTableColumn.headerCell.stringValue == column
  18. object = @objects[rowIndex]
  19. return object[column]
  20. end
  21. end
  22. end
  23.  
  24. # Usage:
  25. #
  26. # Creates the object that will go into the array. Mind you, the key values must be named the same way as the columns in the NSTableView, which is why it might be a good idea to use the actual @columns array post a identifiers.
  27. object = {
  28. @columns[0] => "Put...",
  29. @columns[1] => "...your...",
  30. @columns[2] => "...values...",
  31. @columns[3] => "...here"
  32. }
  33.  
  34. # Adds the object to the @objects array
  35. @objects += [object]
  36.  
  37. # Updates the NSTableView after a new post/row has been added to the storage array
  38. @tableViewOutlet.reloadData

以上是关于四列NSTableView的RubyCocoa控件方法的主要内容,如果未能解决你的问题,请参考以下文章

自动释放池导致 RubyCocoa 应用程序崩溃

NSTableView 内的 NSTableViewCell

用RubyCocoa制作从窗口淡出的动画

RubyCocoa将NSSortDescriptor应用于ruby数组。

MacOS-NSOutlineView使用

拖出 NSTableView 以移除