在Swift中自动将逗号添加到TextField [英] Comma Automatically Being Added to TextField in Swift

查看:92
本文介绍了在Swift中自动将逗号添加到TextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理状态栏应用程序。目前,我所拥有的只是一个下拉菜单,可以退出应用程序或打开首选项窗口。窗口中有一个文本字段,用于数字值。在测试时,我注意到当我使用.orderOut隐藏窗口时,我的数字中会出现一个逗号。不知道为什么会这样或者我能做些什么来阻止它(我对Swift还是很陌生)

I'm working on a status bar application. Currently all I have is a drop down menu that either quits the app or opens a preferences window. There is a textfield in the window that will be for a number value. While testing I noticed that when I used .orderOut to hide the window a comma would appear in my number. No idea why this is happening or what I can do to stop it (I am very new to Swift)

@IBOutlet weak var statusMenu: NSMenu!
@IBOutlet weak var prefWindow: NSWindow!
@IBOutlet weak var artSizeStepper: NSStepper!
@IBOutlet weak var artSizeTextField: NSTextField!

var artSize = 1000;

let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-1) // NSVariableStatusItemLength

func applicationDidFinishLaunching(aNotification: NSNotification) {
    let icon = NSImage(named: "statusIcon")
    icon?.setTemplate(true) // best for dark mode
    statusItem.image = icon
    statusItem.menu = statusMenu
    self.prefWindow!.orderOut(self)
}

func applicationWillTerminate(aNotification: NSNotification) {
    // Insert code here to tear down your application
}

@IBAction func quitClicked(sender: NSMenuItem) {
    NSApplication.sharedApplication().terminate(self)
}
@IBAction func setPrefWindowVisible(sender: NSMenuItem) {
    self.prefWindow!.orderFront(self)
}
@IBAction func stepArtSize(sender: NSStepper) {
    self.artSizeTextField!.setValue(2000)
}
@IBAction func textArtSize(sender: NSTextField) {
}
@IBAction func cancelPrefChange(sender: NSButton) {
    self.prefWindow!.orderOut(self)
}


推荐答案

在情节提要中选择 artSizeTextField 并删除其格式化程序。

In your storyboard select the artSizeTextField and remove its formatter.

这篇关于在Swift中自动将逗号添加到TextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆