swift - NSOpenPanel as sheet -



swift - NSOpenPanel as sheet -

ive looked around @ other answers, nil seems helping case.

i have viewcontroller class contains ibaction button. button should open nsopenpanel sheet viewcontroller:

class viewcontroller: nsviewcontroller { @ibaction func folderselection(sender: anyobject) { var myfiledialog: nsopenpanel = nsopenpanel() myfiledialog.prompt = "select path" myfiledialog.workswhenmodal = true myfiledialog.allowsmultipleselection = false myfiledialog.canchoosedirectories = true myfiledialog.canchoosefiles = false myfiledialog.resolvesaliases = true //myfiledialog.runmodal() myfiledialog.beginsheetmodalforwindow(self.view.window!, completionhandler: nil) var chosenpath = myfiledialog.url if (chosenpath!= nil) { var thefile = chosenpath!.absolutestring! println(thefile) //do thefile } else { println("nothing chosen") } } }

the problem comes myfiledialog.beginsheetmodalforwindow(..) , works line above, not sheet effect

you need phone call beginsheetmodalforwindow panel on window, , utilize completion block:

let myfiledialog = nsopenpanel() myfiledialog.prompt = "select path" myfiledialog.workswhenmodal = true myfiledialog.allowsmultipleselection = false myfiledialog.canchoosedirectories = true myfiledialog.canchoosefiles = false myfiledialog.resolvesaliases = true myfiledialog.beginsheetmodalforwindow(window, completionhandler: { num in if num == nsmodalresponseok { allow path = myfiledialog.url print(path) } else { print("nothing chosen") } })

swift nsopenpanel

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -