I've only been coding for a few weeks so forgive my no-doubt clumsy code.
I have a NSTextField
that needs to update based upon a selection from an NSPopupButton
These are my outlets:
@IBOutlet weak var inputText: NSTextField!
@IBOutlet weak var outputText: NSTextField!
@IBOutlet weak var inputBrowseButton: NSButton!
@IBOutlet weak var outputBrowseButton: NSButton!
@IBOutlet weak var codecSelector: NSPopUpButton!
These are my variables:
// derive default path and filename from @IBAction of inputBrowseButton
var defaultUrl: URL!
// derived from default of inputBrowse unless outputBrowse is used
var outputUrl: URL!
// change output path from @IBAction of outputBrowseButton
var outputDirectory: URL!
// change path extension from @IBAction of codecSelector NSPopupButton
var codecChosen: String = ""
// dictionary of arguments to form script for ffmpeg
var ffmpegCodecArg: String = ""
And here is my method to pull all that together:
// construct output path for use in ffmpegArguments dictionary and display in outputText NSTextField
func updateOutputText(defaultUrl: URL?, outputDirectory: URL?) -> String {
if defaultUrl != nil && outputDirectory != nil {
let outputFile = defaultUrl!.deletingPathExtension()
let outputFilename = outputFile.lastPathComponent
outputUrl = outputDirectory!.appendingPathComponent(outputFilename)
outputText.stringValue = outputUrl.path + "\(codecChosen)"
} else if defaultUrl == nil && outputDirectory != nil {
outputText.stringValue = outputDirectory!.path
} else {
outputUrl = defaultUrl!.deletingPathExtension()
outputText.stringValue = outputUrl.path + "\(codecChosen)"
}
return outputText.stringValue
}
Now at the present this function isn't working because I haven't figured out how to call it yet. But that's an issue for another time, not what I'm asking about here.
Previously I was running
outputUrl = defaultUrl!.deletingPathExtension()
outputText.stringValue = outputUrl.path + "\(codecChosen)"
as part of my inputBrowseButton
@IBAction
method, and I was running
let outputFile = defaultUrl!.deletingPathExtension()
let outputFilename = outputFile.lastPathComponent
outputUrl = outputDirectory!.appendingPathComponent(outputFilename)
outputText.stringValue = outputUrl.path + "\(codecChosen)"
as part of my outputBrowseButton
@IBAction
method.
Which worked fine, EXCEPT when it came to updating outputText.stringValue
when the codecChosen
variable was assigned a new value in my @IBAction
for the codecSelector
NSPopupButton
method.
I suspect the problem is that I don't have my outputText
NSTextField
set up to update when the codecSelector
NSPopupButto
n changes. What do I need to do to make that happen?