NSTextField,在 Swift 中更改文本 [英] NSTextField, Change text in Swift

查看:57
本文介绍了NSTextField,在 Swift 中更改文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

推荐答案

NSTextField 与 UITextField 不同.它没有 text 属性.然而,它确实继承自 NSControl,后者具有 stringValue 属性.

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

这篇关于NSTextField,在 Swift 中更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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