In my document based application, I have added a Label (NSTextField
) to my document's window's titlebar using the new API for 10.10 :
I call this from my main NSViewController
that I have controlling the main view that comes with the window for free :
class MasterViewControler: NSViewController {
@IBOutlet weak var window: NSWindow!
override func viewDidLoad() {
super.viewDidLoad()
window.addTitlebarAccessoryViewController(TitleBarSubviewControler(nibName: "TitleBarSubview", bundle: NSBundle.mainBundle())!)
}
So that loads the custom view containing my label into my titlebar as the docs suggest. All good so far.
Now at some point I must access that label at runtime to change it's string value, from somewhere within my app.
I tried adding an IBOutlet
for the label to the NSTitlebarAccessoryViewController
that controls the subview, and as expected from the NSTitlebarAccessoryViewController
I can manipulate the labels stringValue
. But I can't do much from there.
I tried creating a function in the NSTitlebarAccessoryViewController
that sets the label string, and accessing that function via a global instance of the NSTitlebarAccessoryViewController()
from my mainViewControler
, but although I can access this function and pass it a string, the reference the the labels IBOutlet
in the function always unwraps as nil (crash).
So why is the outlet unwrapping as nil in the function when access from anywhere but inside the class where the function resides.?
I must be able to access the label from a controller or view within my windows mainView
.
How can I do this..?