1

I am trying to set up a large number of columns in an NSOutline/TableView and want to set the formatting for the columns programmatically to a custom NSNUMBERFORMAT (or even to a generic nsnumberformat that has presets) I have tried variations of the following:

            let nf = NSNumberFormatter()
            nf.numberStyle = .PercentStyle
            let c = col.dataCell as! NSTextFieldCell
            c.formatter = nf
            if let tableCellView = analyticResultsOutlineView.makeViewWithIdentifier("Two",owner: self) as? NSTableCellView? {
                if let textField = tableCellView?.textField {
                       textField.cell!.formatter = nf
                }
            }

I have been successful at binding the formatter and dropping it under the nstextfieldcell but even then, the bound singleton custom formatter appeared to change with different columns.

Any help would be appreciated.

  • The formatter isn't a singleton. A tableview is view based or cell based, you can't have both. Create one formatter, in the XIB or in code, store it in a property of the tableview delegate and assign this formatter to the textField. – Willeke Jun 19 '16 at 21:38
  • Similar question: [Sharing an NSDateFormatter between NSTextFields in view-based NSTableView?](http://stackoverflow.com/questions/22123642/sharing-an-nsdateformatter-between-nstextfields-in-view-based-nstableview/22123738#22123738) – Willeke Jun 19 '16 at 21:39

0 Answers0