/ Published in: Ruby
Expand |
Embed | Plain Text
# What you NEED in the controller to be able to list someting in a NSTableView in RubyCocoa # # Creates the storage array, and another array which contains the names of the columns. def initialize @objects = Array.new @columns = ["Column Name 1", "Column Name 2", "Column Name 3", "Column Name 4"] end # Returns the numbers of rows in the array for NSTableView to display. def numberOfRowsInTableView(aTableView) return @objects.length end # Uses the @columns array to to enable a flexible number of columns when fetching data. def tableView_objectValueForTableColumn_row(afileTable, aTableColumn, rowIndex) @columns.each do |column| if aTableColumn.headerCell.stringValue == column object = @objects[rowIndex] return object[column] end end end # Usage: # # 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. object = { @columns[0] => "Put...", @columns[1] => "...your...", @columns[2] => "...values...", @columns[3] => "...here" } # Adds the object to the @objects array @objects += [object] # Updates the NSTableView after a new post/row has been added to the storage array @tableViewOutlet.reloadData
Comments
Subscribe to comments
You need to login to post a comment.

hi, i have a code for nstableview, but it won't reload any data on the table columns and my program stops on responding.. need a little help... i tried to used the code you have posted but still nothing happens... by the way i am using rubycocoa... thanks
it stops somewhere when calling this function: tableViewobjectValueForTableColumnrow(afileTable, aTableColumn, rowIndex)