NSTextField, Change text in Swift

陌路散爱 提交于 2019-12-29 03:21:59

问题


I can't seem to be able to change the text Label in a Mac app that I am trying to make. I am using swift. Here is the code I am using:

@IBOutlet var sumlab: NSTextField!
sumlab.text = "\(result.sum)"     // result.sum is the result of a function I made
// I also tried this:
sumlab.text("\(result.sum)")
// and this:
sumlab.insertText("\(result.sum)")  

None of these seem to work and this is the only problem I need to solve to finish my program. P.S. when i write sumlab.text it says NSTextField does not have a member named text


回答1:


NSTextField is different from a UITextField. It doesn't have a text property. It does however inherit from NSControl which has a stringValue property.

sumlab.stringValue = "\(result.sum)"


来源:https://stackoverflow.com/questions/26536572/nstextfield-change-text-in-swift

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