最近実装しました:https ://github.com/gpambrozio/BlockAlertsAnd-ActionSheets
必要なすべてのファイルをアプリにインポートし、正常にコンパイルしました。問題は、ロジックの変更にどのように対処するかです。
そのため、以前はAppleのUIAlertViewを使用して、次のようなことをしました。
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Which Key?" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
for (NSMutableDictionary *dict in myArray) {
[alertView addButtonWithTitle:[dict objectForKey:@"Key"]];
}
[alertView show];
[alertView release];
次に、alertviewのコールバックでこれを行います。
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
[[Singleton sharedSingleton] setKey:buttonIndex];
}
ボタンBlockAlertView
が押されたコールバックがないため、ボタンの押下を処理する方法は、以下に示すように、実行するコードをブロックに配置することです。とにかく、これは同様のBlockAlertViewがどのように見えるかです:
BlockAlertView *alertView = [BlockAlertView alertWithTitle:@"Which Key?" message:nil];
for (NSMutableDictionary *dict in myArray) {
[alertView addButtonWithTitle:[dict objectForKey:@"Key"] block:^{
//Not sure what to do here
}];
}
[alertView show];
これが私が何をすべきかわからないことです。そのブロックで、AppleのネイティブUIAlertViewで以前に行ったことをどのように達成しますか?ボタンのインデックスにアクセスできず、ボタンの名前にもアクセスできません(インデックスが必要なため、私の場合はそうはいきません)
とにかく、AppleのネイティブUIAlertViewで行ったことを、BlockAlertViewのロジックでどのように行う必要がありますか?
ありがとう!
Edit1 @Christian Pappenberger:
これはBlockAlertViewの.hであり、間違っていない限り、追加できるプロトコルはないと思います。ここにあります:
@interface BlockAlertView : NSObject {
@protected
UIView *_view;
NSMutableArray *_blocks;
CGFloat _height;
}
+ (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message;
- (id)initWithTitle:(NSString *)title message:(NSString *)message;
- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block;
- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block;
- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block;
- (void)show;
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
@property (nonatomic, retain) UIImage *backgroundImage;
@property (nonatomic, readonly) UIView *view;
@property (nonatomic, readwrite) BOOL vignetteBackground;
@end