我开始使用Rubymotion开发,我正在使用自定义单元格创建第一个NSTableView
。
以下代码正常运行,但我无法看到如何使用Teacup布局声明NSTableCellView
(为了在样式表中移动帧大小)
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
我已经尝试过这段代码,但它无效:
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
感谢您的帮助
答案 0 :(得分:0)
如果您指定样式表并调用reapply!
cell.stylesheet = :stylesheet
cell.reapply!