2017-02-14 91 views
0

在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

回答

2

這是NS按鈕沒有setTitle:for:方法像UI按鈕,只有title屬性:

transmitButton.title = "On" 
+0

這很簡單。我半個小時都在敲我的頭。非常感謝。 –

+1

總是建議查看文檔(⌥-或⌘-單擊符號)或⇧⌘0或⇧⌘O並鍵入「NSButton」。有很多方法。 – vadian

+0

這很有幫助..再次感謝。 –

相關問題