Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change text of NSButton in NSTableCellView after click

I have a table of custom NSTableCellViews that contain embedded NSProgressIndicators and NSButtons that I would like to update both immediately after a click, and periodically, on a timer. This is a sample of my code thus far:

func sound(sound: NSSound, didFinishPlaying aBool: Bool) {
    pbNowPlaying.doubleValue = sound.currentTime
    if aBool == true {
        self.btnPlay.stringValue = "Play"
        self.btnPlay.state = NSOffState
        self.pbNowPlaying.doubleValue = 0
    }
    self.needsDisplay = true
}

This (and other code where self.needsDisplay = true is set) does not seem to update the view. When I manually reload the table data, the progress bar moves (having been bound to the NSSounds .currentTime value), but the button text/state does not change.

Any advice?

Coding using Swift, Xcode 6.4, OS X 10.10.4

like image 657
Matt Avatar asked Oct 28 '25 23:10

Matt


1 Answers

Well, I feel rather dumb, but for anyone else who might be running into the same problem: To modify the text on an NSButton, you need to change the .title property, not the .stringValue property.

like image 170
Matt Avatar answered Oct 31 '25 15:10

Matt