/PSAlertView

Wrapper for UIAlertView with Blocks

Primary LanguageObjective-C

From http://petersteinberger.com/2010/03/blocks-on-the-iphone-psalertview/`

It took a while to get my head around blocks. And it didn't help that they are not officially available on the iPhone. But savvy devs from Plausible Labs back-ported the GCC extensions that were added to support blocks to the iPhone. And it's AppStore-safe and they are developing it actively, now adapting it for the iPad. (I already blogged about it)

Today I coded the first actually useful component for blocks. PSAlertView - a wrapper for UIAlertView, no more need for custom delegates. It's so natural if you think about it.

Some code so you get the idea:

PSAlertView *alert = [PSAlertView alertWithTitle:alertTitle message:alertMessage];
[alert setCancelButtonWithTitle:NSLocalizedString(@"Ok", @"") block:^{}];
[alert addButtonWithTitle:NSLocalizedString(@"Retry", @"") block: ^{
[self sendMessage:message];
}];
[alert show];

No more custom delegates, no need to set the protocol in the class header. You can use variables from the function surrounding the block (message) and there's no performance impact.

I'm posting it on github right now, come back to get the code later today.

It's loosely based on PLActionSheet, thanks to Landon Fuller for the tutorials.