Update Formatter during NSOutlineView column resize

I have a column in an NSOutlineView with NSTextFields formatted by a DateFormatter.

When the column gets wider or more narrow, I would like the formatter style to live update. I thought the best place to respond to column resizing would be in the NSTextField viewWillDraw(). And it works beautifully when the column resizes. Unfortunately, it only works for text fields that are visible. When you scroll the table view, those text fields that were out of sight never changed.

Here's what I have so far.

override func viewWillDraw() {
    super.viewWillDraw()
    guard let formatter = formatter as? DateFormatter else { return }

    switch self.visibleRect.width {
    case 0.0..<DateTextField.shortFormatWidth:
        formatter.dateStyle = .none
        formatter.timeStyle = .short
    case DateTextField.shortFormatWidth..<DateTextField.mediumFormatWidth:
        formatter.dateStyle = .short
        formatter.timeStyle = .short
    case DateTextField.mediumFormatWidth..<DateTextField.longFormatWidth:
        formatter.dateStyle = .medium
        formatter.timeStyle = .short
    default:
        formatter.dateStyle = .long
        formatter.timeStyle = .short
    }
}

I also thought reloading the outline view after the column resizing ended would take care of things, but that did not seem to work.

Thanks in advance.

链接地址: http://www.djcxy.com/p/85218.html

上一篇: 如何以简单的方式将CGPoint对象添加到NSArray?

下一篇: 在NSOutlineView列调整大小期间更新格式化程序