Comma Automatically Being Added to TextField in Swift

给你一囗甜甜゛ 提交于 2019-12-11 04:05:01

问题


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)
}

回答1:


In your storyboard select the artSizeTextField and remove its formatter.



来源:https://stackoverflow.com/questions/30688428/comma-automatically-being-added-to-textfield-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!