Dan Wood is co-owner of Karelia Software, creating programs for the Macintosh computer. He is the father of two kids, lives in the Bay Area of California USA, and prefers bicycles to cars. This site is his weblog, which mostly covers geeky topics like Macs and Mac Programming.
Useful Tidbits and Egotistical Musings from Dan Wood
Categories: Business · Mac OS X · Cocoa Programming · General · All Categories
permanent link
· Topic/Cocoa
|
One user interface element that has become common in Mac applications is a warning alert sheet with a checkbox saying "Do not show this warning again" (or words to that effect). The idea is that the user is given ample warning about some impending action, but is given the opportunity to prevent future warnings.
The general idea is to bring up an alert sheet by loading a custom nib with the checkbox in it, and to have the preference to stop showing the sheet attached to a NSUserDefaults key. That's pretty straightforward. The question is how to create the sheet and invoke the action after confirmation, while keeping the calling code as simple as possible.
I came up with an interesting approach to the problem, using an approach similar to a Trampoline Object. Essentially, you replace a warning-less call to a method:
[self doSomeWarnableAction:param1]
with a call like (simplified here):
[[self confirmFirst (...) ]
doSomeWarnableAction:param1];