可可错误:类型的值“NSButton”没有成员“的setTitle”

问题描述:

在Swift3,我有一个按钮声明如下:可可错误:类型的值“NSButton”没有成员“的setTitle”

@IBOutlet weak var transmitButton: NSButton! 

我试图把它的标题:

func textViewDidChange(_ textView: NSTextView) { 
     // If we're already transmitting, stop 
     if transmitButton.state == NSOnState { 
      transmitButton.setNextState() 
      transmitButton.setTitle("On", for: .normal) 
     } 
    } 

,我得到这个错误:

Value of type 'NSButton' has no member 'setTitle' 

我会很感激的任何想法/

+0

所有你需要做的是设置标题,无需对的setTitle :'transmitButton.title =“On”' – RichAppz

这是NS按钮没有setTitle:for:方法像UI按钮,只有title属性:

transmitButton.title = "On" 
+0

这很简单。我半个小时都在敲我的头。非常感谢。 –

+1

总是建议查看文档(⌥-或⌘-单击符号)或⇧⌘0或⇧⌘O并键入“NSButton”。有很多方法。 – vadian

+0

这很有帮助..再次感谢。 –