我刚刚实施:https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets自定义UIAlertView无委托回调?
我已经将所有必要的文件导入到我的应用程序并编译好。现在的问题是,我该如何处理逻辑改变?
因此,与苹果公司的UIAlertView中之前,我做了这样的事情:在alertview的回调
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];
然后,我会做到这一点:
- (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];
现在这里是什么,我不知道该怎么做,该块我该如何实现我与苹果自带的UIAlertView中以前那样?我无法访问按钮索引,我也无法访问按钮的名称(不像那样会帮助我的情况,因为我需要索引)
无论如何,我应该如何去做什么我用苹果的原生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
感谢,似乎工作。也只是如此,我知道未来,我将如何执行某些代码取决于特定的按钮标题,但我不确定它的索引?例如:在clickedButtonAtIndex中,我可以检查特定的按钮标题字符串,并根据它进行编码。我不确定在这种情况下我该如何做到这一点。 – 2012-08-05 21:24:32
我编辑了我的答案,所以我可以添加更多的代码 – tomidelucca 2012-08-05 21:43:12
对不起,我想我不清楚当问你这个问题! :/无论如何,让我重新修饰它。所以可以说我们有一个包含NSMutableDictionary的NSArray。字典中有一个名为“Color”的关键字,阵列中有4个NSMutableDictionarys,总体上有颜色:蓝色,橙色,红色,绿色。所以然后我通过数组使用for循环(就像我用myArray做的那样),在那里添加一个标题为“Color”中的NSString的按钮。所以现在我们添加了所有的按钮,我想在按下“Red”时执行某些代码。有了UIAlertView,我会通过检查 – 2012-08-05 21:55:14