0
votes

When you use default cell-based NSTableView and double click resizing spot in column, that column will resize to that width what is max longest text in your content.

What function I must call in view-based NSTableView to get same effect?

Edit: Function what I missed was:

func tableView(tableView: NSTableView, sizeToFitWidthOfColumn column:Int) -> CGFloat

But how can I get max width from my all stringValues?

1

1 Answers

1
votes

You can get the maximum width of all rows in a column like this:

var width: CGFloat = 0
for i in 0...(tableView.numberOfRows-1) {
    let view = tableView.viewAtColumn(column, row: i, makeIfNecessary: true) as! NSTableCellView
    let size = view.textField!.attributedStringValue.size()
    width = max(width, size.width)
}
return width+20 //add an optional padding