RubyMotion - Styling NSTableCellView with Teacup

113 Views Asked by At

I'm beginning with Rubymotion development, and I'm creating my first NSTableView with custom cells.

The following code is working, but I cannot manage to see how I should declare the NSTableCellView with Teacup layout (in order to move frame size in my stylesheet)

def tableView(table_view, viewForTableColumn: column, row: row_index)
  cell_identifier = 'cell_id'
  cell = table_view.makeViewWithIdentifier(cell_identifier, owner: self)

  unless cell
    cell = NSTableCellView.alloc.initWithFrame(CGRectMake(0, 0, table_view.bounds.size.width, rowHeight))
    cell.identifier = cell_identifier
    layout(cell) do
      subview(NSTextField, :cell_text)
    end
  end

  cell.subviews[0].stringValue = "value for #{row_index}"
  cell
end

I already tried this code but it's not working:

def tableView(table_view, viewForTableColumn: column, row: row_index)
  cell_identifier = 'cell_id'
  @cell = table_view.makeViewWithIdentifier(cell_identifier, owner: self)

  unless @cell
    layout(nil, :root) do
      @cell = subview(NSTableCellView, :cell_view) do |cell|
        cell.identifier = cell_identifier
        subview(NSTextField, :cell_text)
      end
    end
  end

  @cell.subviews[0].stringValue = "value for #{row_index}"
  @cell
end

Thanks for your help

1

There are 1 best solutions below

0
On

It should work if you assign the stylesheet and call reapply!

cell.stylesheet = :stylesheet
cell.reapply!