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;
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
|
show 5 more comments
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
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 ofNumberFormatter
?
– Willeke
Mar 25 at 11:16
|
show 5 more comments
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
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
swift xcode interface-builder nstableview nsnumberformatter
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 ofNumberFormatter
?
– Willeke
Mar 25 at 11:16
|
show 5 more comments
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 ofNumberFormatter
?
– 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
|
show 5 more comments
1 Answer
1
active
oldest
votes
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!.
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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!.
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.
add a comment |
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!.
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.
add a comment |
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!.
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.
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!.
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.
edited Mar 25 at 13:23
answered Mar 25 at 13:04
hockerhocker
367418
367418
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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