何のことだかわからないと思うのでまずサンプルソースをどうぞ。
// Create an alert view
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:
@"Hello World!" message: @"This alert's delegate is implemented using blocks.
That's so cool!" delegate: nil cancelButtonTitle: @"Meh." otherButtonTitles: @"Woo!", nil];
// Get the dynamic delegate
A2DynamicDelegate *dd = alertView.dynamicDelegate;
// Implement -alertViewShouldEnableFirstOtherButton:
[dd implementMethod: @selector(alertViewShouldEnableFirstOtherButton:)
withBlock: ^(UIAlertView *alertView) {
NSLog(@"Message: %@", alertView.message);
return YES;
}];
// Implement -alertView:willDismissWithButtonIndex:
[dd implementMethod: @selector(alertView:willDismissWithButtonIndex:)
withBlock: ^(UIAlertView *alertView, NSInteger buttonIndex) {
NSLog(@"You pushed button #%d (%@)", buttonIndex, [alertView buttonTitleAtIndex: buttonIndex]);
}];
// Set the delegate
alertView.delegate = dd;
[alertView show];
[alertView release];
サンプルでは UIAlertViewDelegate を Blcoksに変換している。そう、つまり任意の Delegate(Datasource)メソッドを Blocksで記述できるようにするのがこのライブラリ。カスタムblocksプロパティをカテゴリとして実装すればこんな記述もできるようになる。
// Create an alert view
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:
@"Hello World!" message: @"This alert's delegate is implemented using blocks.
That's so cool!" delegate: nil cancelButtonTitle: @"Meh." otherButtonTitles: @"Woo!", nil];
// Implement -alertViewShouldEnableFirstOtherButton:
alertView.shouldEnableFirstOtherButtonBlock = ^(UIAlertView *alertView) {
NSLog(@"Message: %@", alertView.message);
return YES;
};
// Implement -alertView:willDismissWithButtonIndex:
alertView.willDismissBlock = ^(UIAlertView *alertView, NSInteger buttonIndex) {
NSLog(@"You pushed button #%d (%@)", buttonIndex, [alertView buttonTitleAtIndex: buttonIndex]);
};
// Set the delegate
alertView.delegate = alertView.dynamicDelegate;
[alertView show];
[alertView release];
※UIAlertView+A2BlockDelegate.(h|m)の実装が必要。これはアイディアが面白い。
ライセンス:Simplified BSD


