Subclassed NumberFormatter in NSTableView not formattingPrecision String Format Specifier In SwiftWhere to add identifier for NSTableView column?Xcode 6 GM storyboard outlets always nilCustom UIView subclass with XIB in SwiftProgrammatically set NSNumberFormatter for NSTableView ColumnsNSTableView outlet subclassed to NSOutlineView in code?Issues with casting celltypes to dequeueIn a view-based NSTableView, the NSTextField is clipped by an NSImageViewAdding a custom UIViewcontroller to subview programmatically but getting an error message “Cannot convert value of type…”How to implement NumberFormatter

How could a possessed body begin to rot and decay while it is still alive?

What do we gain with higher order logics?

Replace only 2nd, 3rd, nth...character and onwards

How bad would a partial hash leak be, realistically?

How to make a setting relevant?

Riley's, assemble!

Does Peach's float negate shorthop knockback multipliers?

Comma Code - Ch. 4 Automate the Boring Stuff

Accidentally cashed a check twice

Old black and white movie: glowing black rocks slowly turn you into stone upon touch

What is a simple, physical situation where complex numbers emerge naturally?

Avoiding cliches when writing gods

PhD student with mental health issues and bad performance

X-shaped crossword

1980s (or earlier) book where people live a long time but they have short memories

How do you build a story from a world?

What's the logic behind the the organization of Hamburg's bus transport into "rings"?

Did thousands of women die every year due to illegal abortions before Roe v. Wade?

Could the Missouri River be running while Lake Michigan was frozen several meters deep?

Working in the USA for living expenses only; allowed on VWP?

What happens to foam insulation board after you pour concrete slab?

Does any lore text explain why the planes of Acheron, Gehenna, and Carceri are the alignment they are?

Chopin: marche funèbre bar 15 impossible place

Does the growth of home value benefit from compound interest?



Subclassed NumberFormatter in NSTableView not formatting


Precision String Format Specifier In SwiftWhere to add identifier for NSTableView column?Xcode 6 GM storyboard outlets always nilCustom UIView subclass with XIB in SwiftProgrammatically set NSNumberFormatter for NSTableView ColumnsNSTableView outlet subclassed to NSOutlineView in code?Issues with casting celltypes to dequeueIn a view-based NSTableView, the NSTextField is clipped by an NSImageViewAdding a custom UIViewcontroller to subview programmatically but getting an error message “Cannot convert value of type…”How to implement NumberFormatter






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have subclassed a NumberFormatter for my specific use and it's working great when I call it from code. Here's the subclass:



 class MyNumberFormatterUnitPrice: NumberFormatter 

required init?(coder aDecoder: NSCoder)
super.init(coder: aDecoder)
setup()


override init()
super.init()
setup()


private func setup()
self.format = "#,##0.00####;(#,##0.00####)"
self.numberStyle = .currencyAccounting





I'm doing this because, while it's possible to set the positive and negative formats in the storyboard, you can't set those and "currencyAccounting". However, when I create a NumberFormatter in the storyboard, choose this subclass and then put it under my text cell for the column I would like to format, it appears to get overridden within:



tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView?


In here, I'm currently setting the cell by this logic:



let cellIdentifier = tableColumn!.identifier.rawValue
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(cellIdentifier), owner: nil) as? NSTableCellView {
...


I believe that I'm getting the tableviewcell from the tableview by its identifier and not creating a new one, so that should have its textfield along with it. I read the documentation and this appears to be the right way to do this. If I set the numberformatter after I've gotten the cell here, it works. But I don't want to do it this way because I don't want a giant case statement to set specific cell properties - I'd like to do this in the storyboard editor.



Any advice on how to use the storyboard editor to set the numberformatter?



Edit: Further to this, I have put a breakpoint inside where I am setting the stringvalue of the textfield, and the text is being set as follows:



textfield.stringValue = text


Looking at where the number formatter is in the debugger, it's set at the table column level - that doesn't seem right. But it's definitely still there and hasn't been written over somehow.



(lldb) e ((tableColumn?.dataCell as! NSTextFieldCell).formatter as! NumberFormatter).format
(String) $R14 = "#,##0.00####;0.00;(#,##0.00####)"


And the textfield's formatter is nil... weird.



(lldb) e textfield.formatter
(Formatter?) $R26 = nil


I'm going to go back and check the storyboard to see if maybe I dropped the formatter in the wrong place.










share|improve this question
























  • Subclass the NSTableViewCell for this column and use your formatter there. (You probably don't need to subclass NumberFormatter, just the table cell class) You can reference the table cell subclass in IB.

    – Ron
    Mar 24 at 14:04












  • .currencyAccounting is just a predefined number format style. In IB set the formatter to OS X 10.4+ Default and Style Currency Accounting. Switch to OS X 10.4+ Custom and customize the format.

    – Willeke
    Mar 24 at 14:57











  • @Ron, I'm looking at subclassing the NSTableViewCell right now.

    – hocker
    Mar 25 at 11:06











  • @Willeke, I have customized the format but as I was saying above, it is being overridden somehow within my code even though I can't figure out how. I'm not creating a new text cell anywhere.

    – hocker
    Mar 25 at 11:06











  • Is the question "how to use the storyboard editor to set the numberformatter?" or do you want to use a subclass of NumberFormatter?

    – Willeke
    Mar 25 at 11:16

















1















I have subclassed a NumberFormatter for my specific use and it's working great when I call it from code. Here's the subclass:



 class MyNumberFormatterUnitPrice: NumberFormatter 

required init?(coder aDecoder: NSCoder)
super.init(coder: aDecoder)
setup()


override init()
super.init()
setup()


private func setup()
self.format = "#,##0.00####;(#,##0.00####)"
self.numberStyle = .currencyAccounting





I'm doing this because, while it's possible to set the positive and negative formats in the storyboard, you can't set those and "currencyAccounting". However, when I create a NumberFormatter in the storyboard, choose this subclass and then put it under my text cell for the column I would like to format, it appears to get overridden within:



tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView?


In here, I'm currently setting the cell by this logic:



let cellIdentifier = tableColumn!.identifier.rawValue
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(cellIdentifier), owner: nil) as? NSTableCellView {
...


I believe that I'm getting the tableviewcell from the tableview by its identifier and not creating a new one, so that should have its textfield along with it. I read the documentation and this appears to be the right way to do this. If I set the numberformatter after I've gotten the cell here, it works. But I don't want to do it this way because I don't want a giant case statement to set specific cell properties - I'd like to do this in the storyboard editor.



Any advice on how to use the storyboard editor to set the numberformatter?



Edit: Further to this, I have put a breakpoint inside where I am setting the stringvalue of the textfield, and the text is being set as follows:



textfield.stringValue = text


Looking at where the number formatter is in the debugger, it's set at the table column level - that doesn't seem right. But it's definitely still there and hasn't been written over somehow.



(lldb) e ((tableColumn?.dataCell as! NSTextFieldCell).formatter as! NumberFormatter).format
(String) $R14 = "#,##0.00####;0.00;(#,##0.00####)"


And the textfield's formatter is nil... weird.



(lldb) e textfield.formatter
(Formatter?) $R26 = nil


I'm going to go back and check the storyboard to see if maybe I dropped the formatter in the wrong place.










share|improve this question
























  • Subclass the NSTableViewCell for this column and use your formatter there. (You probably don't need to subclass NumberFormatter, just the table cell class) You can reference the table cell subclass in IB.

    – Ron
    Mar 24 at 14:04












  • .currencyAccounting is just a predefined number format style. In IB set the formatter to OS X 10.4+ Default and Style Currency Accounting. Switch to OS X 10.4+ Custom and customize the format.

    – Willeke
    Mar 24 at 14:57











  • @Ron, I'm looking at subclassing the NSTableViewCell right now.

    – hocker
    Mar 25 at 11:06











  • @Willeke, I have customized the format but as I was saying above, it is being overridden somehow within my code even though I can't figure out how. I'm not creating a new text cell anywhere.

    – hocker
    Mar 25 at 11:06











  • Is the question "how to use the storyboard editor to set the numberformatter?" or do you want to use a subclass of NumberFormatter?

    – Willeke
    Mar 25 at 11:16













1












1








1








I have subclassed a NumberFormatter for my specific use and it's working great when I call it from code. Here's the subclass:



 class MyNumberFormatterUnitPrice: NumberFormatter 

required init?(coder aDecoder: NSCoder)
super.init(coder: aDecoder)
setup()


override init()
super.init()
setup()


private func setup()
self.format = "#,##0.00####;(#,##0.00####)"
self.numberStyle = .currencyAccounting





I'm doing this because, while it's possible to set the positive and negative formats in the storyboard, you can't set those and "currencyAccounting". However, when I create a NumberFormatter in the storyboard, choose this subclass and then put it under my text cell for the column I would like to format, it appears to get overridden within:



tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView?


In here, I'm currently setting the cell by this logic:



let cellIdentifier = tableColumn!.identifier.rawValue
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(cellIdentifier), owner: nil) as? NSTableCellView {
...


I believe that I'm getting the tableviewcell from the tableview by its identifier and not creating a new one, so that should have its textfield along with it. I read the documentation and this appears to be the right way to do this. If I set the numberformatter after I've gotten the cell here, it works. But I don't want to do it this way because I don't want a giant case statement to set specific cell properties - I'd like to do this in the storyboard editor.



Any advice on how to use the storyboard editor to set the numberformatter?



Edit: Further to this, I have put a breakpoint inside where I am setting the stringvalue of the textfield, and the text is being set as follows:



textfield.stringValue = text


Looking at where the number formatter is in the debugger, it's set at the table column level - that doesn't seem right. But it's definitely still there and hasn't been written over somehow.



(lldb) e ((tableColumn?.dataCell as! NSTextFieldCell).formatter as! NumberFormatter).format
(String) $R14 = "#,##0.00####;0.00;(#,##0.00####)"


And the textfield's formatter is nil... weird.



(lldb) e textfield.formatter
(Formatter?) $R26 = nil


I'm going to go back and check the storyboard to see if maybe I dropped the formatter in the wrong place.










share|improve this question
















I have subclassed a NumberFormatter for my specific use and it's working great when I call it from code. Here's the subclass:



 class MyNumberFormatterUnitPrice: NumberFormatter 

required init?(coder aDecoder: NSCoder)
super.init(coder: aDecoder)
setup()


override init()
super.init()
setup()


private func setup()
self.format = "#,##0.00####;(#,##0.00####)"
self.numberStyle = .currencyAccounting





I'm doing this because, while it's possible to set the positive and negative formats in the storyboard, you can't set those and "currencyAccounting". However, when I create a NumberFormatter in the storyboard, choose this subclass and then put it under my text cell for the column I would like to format, it appears to get overridden within:



tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView?


In here, I'm currently setting the cell by this logic:



let cellIdentifier = tableColumn!.identifier.rawValue
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(cellIdentifier), owner: nil) as? NSTableCellView {
...


I believe that I'm getting the tableviewcell from the tableview by its identifier and not creating a new one, so that should have its textfield along with it. I read the documentation and this appears to be the right way to do this. If I set the numberformatter after I've gotten the cell here, it works. But I don't want to do it this way because I don't want a giant case statement to set specific cell properties - I'd like to do this in the storyboard editor.



Any advice on how to use the storyboard editor to set the numberformatter?



Edit: Further to this, I have put a breakpoint inside where I am setting the stringvalue of the textfield, and the text is being set as follows:



textfield.stringValue = text


Looking at where the number formatter is in the debugger, it's set at the table column level - that doesn't seem right. But it's definitely still there and hasn't been written over somehow.



(lldb) e ((tableColumn?.dataCell as! NSTextFieldCell).formatter as! NumberFormatter).format
(String) $R14 = "#,##0.00####;0.00;(#,##0.00####)"


And the textfield's formatter is nil... weird.



(lldb) e textfield.formatter
(Formatter?) $R26 = nil


I'm going to go back and check the storyboard to see if maybe I dropped the formatter in the wrong place.







swift xcode interface-builder nstableview nsnumberformatter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 12:57







hocker

















asked Mar 24 at 13:07









hockerhocker

367418




367418












  • Subclass the NSTableViewCell for this column and use your formatter there. (You probably don't need to subclass NumberFormatter, just the table cell class) You can reference the table cell subclass in IB.

    – Ron
    Mar 24 at 14:04












  • .currencyAccounting is just a predefined number format style. In IB set the formatter to OS X 10.4+ Default and Style Currency Accounting. Switch to OS X 10.4+ Custom and customize the format.

    – Willeke
    Mar 24 at 14:57











  • @Ron, I'm looking at subclassing the NSTableViewCell right now.

    – hocker
    Mar 25 at 11:06











  • @Willeke, I have customized the format but as I was saying above, it is being overridden somehow within my code even though I can't figure out how. I'm not creating a new text cell anywhere.

    – hocker
    Mar 25 at 11:06











  • Is the question "how to use the storyboard editor to set the numberformatter?" or do you want to use a subclass of NumberFormatter?

    – Willeke
    Mar 25 at 11:16

















  • Subclass the NSTableViewCell for this column and use your formatter there. (You probably don't need to subclass NumberFormatter, just the table cell class) You can reference the table cell subclass in IB.

    – Ron
    Mar 24 at 14:04












  • .currencyAccounting is just a predefined number format style. In IB set the formatter to OS X 10.4+ Default and Style Currency Accounting. Switch to OS X 10.4+ Custom and customize the format.

    – Willeke
    Mar 24 at 14:57











  • @Ron, I'm looking at subclassing the NSTableViewCell right now.

    – hocker
    Mar 25 at 11:06











  • @Willeke, I have customized the format but as I was saying above, it is being overridden somehow within my code even though I can't figure out how. I'm not creating a new text cell anywhere.

    – hocker
    Mar 25 at 11:06











  • Is the question "how to use the storyboard editor to set the numberformatter?" or do you want to use a subclass of NumberFormatter?

    – Willeke
    Mar 25 at 11:16
















Subclass the NSTableViewCell for this column and use your formatter there. (You probably don't need to subclass NumberFormatter, just the table cell class) You can reference the table cell subclass in IB.

– Ron
Mar 24 at 14:04






Subclass the NSTableViewCell for this column and use your formatter there. (You probably don't need to subclass NumberFormatter, just the table cell class) You can reference the table cell subclass in IB.

– Ron
Mar 24 at 14:04














.currencyAccounting is just a predefined number format style. In IB set the formatter to OS X 10.4+ Default and Style Currency Accounting. Switch to OS X 10.4+ Custom and customize the format.

– Willeke
Mar 24 at 14:57





.currencyAccounting is just a predefined number format style. In IB set the formatter to OS X 10.4+ Default and Style Currency Accounting. Switch to OS X 10.4+ Custom and customize the format.

– Willeke
Mar 24 at 14:57













@Ron, I'm looking at subclassing the NSTableViewCell right now.

– hocker
Mar 25 at 11:06





@Ron, I'm looking at subclassing the NSTableViewCell right now.

– hocker
Mar 25 at 11:06













@Willeke, I have customized the format but as I was saying above, it is being overridden somehow within my code even though I can't figure out how. I'm not creating a new text cell anywhere.

– hocker
Mar 25 at 11:06





@Willeke, I have customized the format but as I was saying above, it is being overridden somehow within my code even though I can't figure out how. I'm not creating a new text cell anywhere.

– hocker
Mar 25 at 11:06













Is the question "how to use the storyboard editor to set the numberformatter?" or do you want to use a subclass of NumberFormatter?

– Willeke
Mar 25 at 11:16





Is the question "how to use the storyboard editor to set the numberformatter?" or do you want to use a subclass of NumberFormatter?

– Willeke
Mar 25 at 11:16












1 Answer
1






active

oldest

votes


















0














OK that got it. I'm obviously a noob to MacOS development and I just trusted that dropping the number formatter into the column I wanted was going to put it at the cell level... that's NOT true!.



enter image description here



In this image you can see the right and the wrong way to do this if you're expecting to format the cell. The right way is highlighted. You have to open the hierarchy up right down to the text field for the cell. The wrong way is above and you'll see it under the "text cell" which is actually the text cell for the column.



Thanks for everyone who stuck with me and tried help me on this. I hope this answer helps others in the future avoid several days of frustration like I just had!



Also as @Willeke points out, there's no real need to subclass the numberformatter if all you're doing is setting these properties. I'm going to do it because I have lots of cells that I want to share a common format but if all you're doing is formatting one cell, it's not needed.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324102%2fsubclassed-numberformatter-in-nstableview-not-formatting%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    OK that got it. I'm obviously a noob to MacOS development and I just trusted that dropping the number formatter into the column I wanted was going to put it at the cell level... that's NOT true!.



    enter image description here



    In this image you can see the right and the wrong way to do this if you're expecting to format the cell. The right way is highlighted. You have to open the hierarchy up right down to the text field for the cell. The wrong way is above and you'll see it under the "text cell" which is actually the text cell for the column.



    Thanks for everyone who stuck with me and tried help me on this. I hope this answer helps others in the future avoid several days of frustration like I just had!



    Also as @Willeke points out, there's no real need to subclass the numberformatter if all you're doing is setting these properties. I'm going to do it because I have lots of cells that I want to share a common format but if all you're doing is formatting one cell, it's not needed.






    share|improve this answer





























      0














      OK that got it. I'm obviously a noob to MacOS development and I just trusted that dropping the number formatter into the column I wanted was going to put it at the cell level... that's NOT true!.



      enter image description here



      In this image you can see the right and the wrong way to do this if you're expecting to format the cell. The right way is highlighted. You have to open the hierarchy up right down to the text field for the cell. The wrong way is above and you'll see it under the "text cell" which is actually the text cell for the column.



      Thanks for everyone who stuck with me and tried help me on this. I hope this answer helps others in the future avoid several days of frustration like I just had!



      Also as @Willeke points out, there's no real need to subclass the numberformatter if all you're doing is setting these properties. I'm going to do it because I have lots of cells that I want to share a common format but if all you're doing is formatting one cell, it's not needed.






      share|improve this answer



























        0












        0








        0







        OK that got it. I'm obviously a noob to MacOS development and I just trusted that dropping the number formatter into the column I wanted was going to put it at the cell level... that's NOT true!.



        enter image description here



        In this image you can see the right and the wrong way to do this if you're expecting to format the cell. The right way is highlighted. You have to open the hierarchy up right down to the text field for the cell. The wrong way is above and you'll see it under the "text cell" which is actually the text cell for the column.



        Thanks for everyone who stuck with me and tried help me on this. I hope this answer helps others in the future avoid several days of frustration like I just had!



        Also as @Willeke points out, there's no real need to subclass the numberformatter if all you're doing is setting these properties. I'm going to do it because I have lots of cells that I want to share a common format but if all you're doing is formatting one cell, it's not needed.






        share|improve this answer















        OK that got it. I'm obviously a noob to MacOS development and I just trusted that dropping the number formatter into the column I wanted was going to put it at the cell level... that's NOT true!.



        enter image description here



        In this image you can see the right and the wrong way to do this if you're expecting to format the cell. The right way is highlighted. You have to open the hierarchy up right down to the text field for the cell. The wrong way is above and you'll see it under the "text cell" which is actually the text cell for the column.



        Thanks for everyone who stuck with me and tried help me on this. I hope this answer helps others in the future avoid several days of frustration like I just had!



        Also as @Willeke points out, there's no real need to subclass the numberformatter if all you're doing is setting these properties. I'm going to do it because I have lots of cells that I want to share a common format but if all you're doing is formatting one cell, it's not needed.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 25 at 13:23

























        answered Mar 25 at 13:04









        hockerhocker

        367418




        367418





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324102%2fsubclassed-numberformatter-in-nstableview-not-formatting%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현