osx - NSWindow returns nil (NSApplication) -
i've come across issue cannot access app's main window, returns nil.
let window = nsapplication.sharedapplication().mainwindow
i've found similar questions:
how main window (app delegate) other class (subclass of nsviewcontroller)?
but doing:
let window = (nsapplication.sharedapplication() as! nsarray).objectatindex(0)
doesn't seem work either.
do have mess around in storyboard?
thanks in advance.
update:
i'm trying port objective-c.
nswindow *mainwindow = [[[nsapplication sharedapplication] windows] objectatindex:0]; nslog(@"%@", mainwindow.contentviewcontroller);
this returns proper value, when put in viewdidload()
block in nsviewcontroller
, i'm guessing there wrong nsapplication.sharedapplication()
.
it can return nil if main app window not active on macos. instance ran when making drag , drop file uploader. if window not in front (on operating system) return nil. following line of code activate app (bring front)
nsapp.activateignoringotherapps(true)
i needed timer delay call of mainwindow in case.
Comments
Post a Comment