xcode 接口生成器中带有自动 NSNumberFormatter 的 NSTextField
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7479882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NSTextField with automatic NSNumberFormatter in Interface Builder
提问by Kenny Wyland
I've been making iOS apps for awhile, but I'm trying my hand at MacOS development. I'm adding an NSTextField to my UI and I noticed in Xcode that one of the options in the graphical widgets is "NSTextField with NSNumberFormatter" which implies to me that I'll be able to restrict the input of the field to numbers and configure the formatter in some way.
我一直在制作 iOS 应用程序,但我正在尝试 MacOS 开发。我正在向我的 UI 添加一个 NSTextField,我在 Xcode 中注意到图形小部件中的一个选项是“NSTextField with NSNumberFormatter”,这意味着我将能够将字段的输入限制为数字并配置格式化程序以某种方式。
When I add the NSTextField with NSNumberFormatter to my UI, I can see it has a formatter outlet which appears to be kind of linked to an NSNumberFormatter (although the name is a little grayed out). However, I can't figure out any way to interact with or configure that NSNumberFormatter.
当我将带有 NSNumberFormatter 的 NSTextField 添加到我的 UI 时,我可以看到它有一个格式化程序出口,它似乎有点链接到 NSNumberFormatter(尽管名称有点变灰)。但是,我想不出任何与 NSNumberFormatter 交互或配置它的方法。
Any help?
有什么帮助吗?
回答by Adam Wilt
To access the NSNumberFormatter, you have to select it in the dock (that list of objects on the left side of the XCode 4 Interface Builder [IB] window).
要访问 NSNumberFormatter,您必须在 Dock 中选择它(XCode 4 Interface Builder [IB] 窗口左侧的对象列表)。
If the dock isn't in outline view, e.g., it just shows about 4 icons, click the triangle-in-a-square-button at the bottom of the dock. The dock should now show a "Placeholders" section and an "Objects" section; the objects are your UI objects in a hierarchical outline view.
如果停靠栏不在大纲视图中,例如,它只显示大约 4 个图标,请单击停靠栏底部的三角形方形按钮。Dock 现在应该显示“Placeholders”部分和“Objects”部分;这些对象是分层大纲视图中的 UI 对象。
In the IB window, click your NSTextField; that'll highlight the corresponding Text Field Cell in the outline (you may have to twiddle down some disclosure triangles to see it). The Text Field Cell should have a disclosure triangle; twiddle it down to reveal the Number Formatter. Select it, and you should now be able to manipulate it in the Inspector panel.
在 IB 窗口中,单击您的 NSTextField;这将突出显示轮廓中相应的文本字段单元格(您可能需要向下旋转一些显示三角形才能看到它)。文本字段单元格应该有一个显示三角形;旋转它以显示数字格式器。选择它,您现在应该可以在 Inspector 面板中操作它。
(There are a lot of things non-obvious like that in XCode. When in doubt, examine your UI object in the Dock's outline view, or prowl the menus with that object selected. It's amazing--and often useful--what you can discover lurking there!
(在 XCode 中有很多不明显的东西。如果有疑问,请在 Dock 的大纲视图中检查您的 UI 对象,或者在选中该对象的情况下浏览菜单。这很神奇——而且通常很有用——你可以做什么发现潜伏在那里!
回答by moritz
to configure the number formatter, you can ( after you've selected the formatter ) open the Attributes inspector, select the behavior you want and customize the formatter. At least that worked for me in XCode 4.
要配置数字格式化程序,您可以(在选择格式化程序后)打开属性检查器,选择所需的行为并自定义格式化程序。至少这在 XCode 4 中对我有用。
– moritz
– 莫里茨