在任何将显示alertview类型的类中提供以下行
#import <DeceptionAlertViews/AlertView.h>
您将使用的显示UIAlertView/UIAlertController的方法将是
+ (void)showAlertWithTitle:(NSString *)title
message:(NSString *)message
cancelBlock:(AlertCancelBlock)alertCancelBlock
completionBlocks:(NSArray *)completionBlocks
cancelButtonTitle:(NSString *)cancelButtonTitle
otherButtonTitles:(NSArray *)otherButtonTitles
presentingViewController:(UIViewController *)presentingViewController
type:(UIAlertControllerStyle)type
animated:(BOOL)animated
completionBlock:(AlertCompletionBlock)alertCompletionBlock;
要返回UIAlertView/UIAlertController,请使用以下
+ (void)returnAlertWithTitle:(NSString *)title
message:(NSString *)message
cancelBlock:(AlertCancelBlock)alertCancelBlock
completionBlocks:(NSArray *)completionBlocks
cancelButtonTitle:(NSString *)cancelButtonTitle
otherButtonTitles:(NSArray *)otherButtonTitles
presentingViewController:(UIViewController *)presentingViewController
type:(UIAlertControllerStyle)type
animated:(BOOL)animated
completionBlock:(AlertCompletionBlock)alertCompletionBlock;
注意:alertCancelBlock 是您将提供的实际 block 或 ^{},completionBlocks 是您将传递的 blocks 的数组,其索引对应于otherButtonTitles数组中按钮的索引。
示例实现
[AlertView returnAlertWithTitle:@"A Title" message:@"A Message" cancelBlock:^{
NSLog(@"cancel block called");
} completionBlocks:@[^{
NSLog(@"block one called");
},^{
NSLog(@"block two called");
},^{
NSLog(@"block three called");
}] cancelButtonTitle:@"cancel" otherButtonTitles:@[@"one", @"two", @"three"] presentingViewController:self animated:YES completionBlock:^{
NSLog(@"completion block called");
}];
这专为支持iOS 4.3至iOS 8的应用程序设计。请使用最新提交(首选)或最新版本。它向后支持iOS 4.3,但该类使用arc,目前不支持非arc应用程序。
DeceptionAlertViews可通过CocoaPods获得。要安装它,只需将以下行添加到您的Podfile中
pod 'DeceptionAlertViews', '~> 0.6.0'
DeceptionAlertViews可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。