swift - NSTextField,在 Swift 中更改文本

标签 swift nstextfield

我似乎无法更改我尝试制作的 Mac 应用程序中的文本标签。 我正在使用快速。这是我正在使用的代码:

@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)")  

这些似乎都不起作用,这是我完成程序所需解决的唯一问题。 附言当我写 sumlab.text 时,它说 NSTextField 没有名为 text 的成员

最佳答案

NSTextField 不同于 UITextField。它没有 text 属性。但是,它确实继承自具有 stringValue 属性的 NSControl。

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

关于swift - NSTextField,在 Swift 中更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26536572/

相关文章:

swift - 将地址从一个 Vc 传递到另一个 Vc

swift - 内部带有描述标签的文本字段

cocoa - 多行 NSTokenField 和返回键

cocoa - 如何调整 NSTextField 的大小以适合它所包含的文本?

swift - NSTextField:将 String 转换为 Int 在 Xcode 外部中止(nil)

cocoa - 使 nstextfield 单行

ios - Swift UITextField 填充顶部

ios - 在 ScrollView 中循环重置(swift 3)

ios - 避免用户注册系统,但需要应用内购买和数据同步

swift - 在 UICollectionViewCell 中实现 UIStackView