我最近刚刚实现: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