{"id":110,"date":"2005-12-31T09:28:07","date_gmt":"2005-12-31T13:28:07","guid":{"rendered":"http:\/\/www.dr-chuck.com\/wordpress\/?p=110"},"modified":"2011-12-17T12:18:51","modified_gmt":"2011-12-17T16:18:51","slug":"doing-a-modal-dialog-in-objective-c","status":"publish","type":"post","link":"https:\/\/www.dr-chuck.com\/csev-blog\/2005\/12\/doing-a-modal-dialog-in-objective-c\/","title":{"rendered":"Doing a Modal Dialog in Objective C"},"content":{"rendered":"<p>See this URL:<br \/>\nhttp:\/\/developer.apple.com\/documentation\/Cocoa\/Conceptual\/Sheets\/Tasks\/UsingAppModalDialogs.html<br \/>\nThis is a better modal dialog than in the Hillegass book pages 306-311.   The Hillegass book is great showing the wiring of such a sheet &#8211; but the code below is better for the actual showing of the dialog.  The Hillegass book uses the selector (nifty pet trick &#8211; but overkill for most modal dialogs).<\/p>\n<p><!--more--><br \/>\nUse this code (I have added some comments below):<br \/>\n&#8211; (void)showCustomDialog: (NSWindow *)window<br \/>\n\/\/ User has asked to see the dialog. Display it.<br \/>\n{<br \/>\nif (!myCustomDialog)<br \/>\n[NSBundle loadNibNamed: @&#8221;MyCustomDialog&#8221; owner: self];<br \/>\n[NSApp beginSheet: myCustomDialog<br \/>\nmodalForWindow: window<br \/>\nmodalDelegate: nil<br \/>\ndidEndSelector: nil<br \/>\ncontextInfo: nil];<br \/>\n[NSApp runModalForWindow: myCustomDialog];<br \/>\n\/\/ Dialog is up here.<br \/>\n\/\/ This coee is executed after the dialog closes<br \/>\n\/\/ Pull final values for variables from of the modal Dialog here<br \/>\n\/\/ Note &#8211; any type of return code needs to be placed in a class-global variable<br \/>\nNSLog([_sheetPasswordTextField stringValue]);<br \/>\nfprintf(stderr,&#8221;Return value = %d\\n&#8221;,sheetResult);<br \/>\n[NSApp endSheet: myCustomDialog];<br \/>\n[myCustomDialog orderOut: self];<br \/>\n}<br \/>\nListing 2  Closing an application-modal dialog<br \/>\n&#8211; (IBAction)closeMyCustomDialog: (id)sender<br \/>\n{<br \/>\n\/\/ If you have more than one button, set a class-global integer<br \/>\n\/\/ to indicate which button was pressed to close the dialog (OK, Login, etc)<br \/>\nsheetResult = 0;<br \/>\n[NSApp stopModal];<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>See this URL: http:\/\/developer.apple.com\/documentation\/Cocoa\/Conceptual\/Sheets\/Tasks\/UsingAppModalDialogs.html This is a better modal dialog than in the Hillegass book pages 306-311. The Hillegass book is great showing the wiring of such a sheet &#8211; but the code below is better for the actual showing of the dialog. The Hillegass book uses the selector (nifty pet trick &#8211; but overkill [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-110","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":1,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/110\/revisions"}],"predecessor-version":[{"id":2208,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/110\/revisions\/2208"}],"wp:attachment":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/media?parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/categories?post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/tags?post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}