The Rules
  • Feel free to leave constructive criticism, or point out a better way to do something.
  • Personal attacks or flames, on me or anyone else, will be deleted.
  • Past history has shown that 99% of comments I can't read (i.e. those in other languages) to be spam. Therefore, any comment I can't read will be removed.
  • I'm pretty mellow concerning profanity, but excessive (as determined subjectively by me), bad language will be removed.

Tuesday, October 28, 2008

Here's a handy little tool I've used often...

Problem: In several applications, I've found the need to pop up an alert/message window telling the application user that something went wrong, or that something they did wasn't kosher.

Solution: NSRunAlertPanel. Little macros like this one are additional reasons I love programming for the Mac. But to make it a little more useful, I created a method call that makes a dummy alert with an ok button and a given message. It looks like this:

-(void) displayAlert:(NSString*) alertMsg {
NSRunAlertPanel(@"Alert", alertMsg, @"OK", nil, nil);

The actual NSRunAlertPanel macro signature looks like this:

NSRunAlertPanel(NSString *title,
NSString *msgFormat,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton)

Other parameters can be added to the method signature to create more full-featured alerts. I created the method solely to remove the NSRunAlertPanel call (which can be a big method call) from the logic of what I'm doing at the moment and replace it with a short method call that does what I want it to.

No comments: