It may not be obvious but UIAlertView could be created and presented in one line of code. The reason is to avoid local variable to hold the view instance while it's created, displayed and autoreleased. Here is the code:

  1. [[[[UIAlertView alloc] initWithTitle:@"Title"
  2.                              message:@"Message"
  3.                             delegate:nil
  4.                    cancelButtonTitle:@"OK"
  5.                    otherButtonTitles:nil] autorelease] show];
[[[[UIAlertView alloc] initWithTitle:@"Title"
                             message:@"Message"
                            delegate:nil
                   cancelButtonTitle:@"OK"
                   otherButtonTitles:nil] autorelease] show];

To make things even simpler I define the following macro for the project:

  1. #define BAAlert(TITLE,MSG) [[[[UIAlertView alloc] initWithTitle:(TITLE) \
  2.               message:(MSG) \
  3.              delegate:nil \
  4.     cancelButtonTitle:@"OK" \
  5.     otherButtonTitles:nil] autorelease] show]
#define BAAlert(TITLE,MSG) [[[[UIAlertView alloc] initWithTitle:(TITLE) \
              message:(MSG) \
             delegate:nil \
    cancelButtonTitle:@"OK" \
    otherButtonTitles:nil] autorelease] show]

Which could be used as simple call:

  1. BAAlert(@"Title", @"Message");
BAAlert(@"Title", @"Message");

That's it.