MTBlockAlertView 0.1.1

MTBlockAlertView 0.1.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布日期最后发布2014年12月

Adam Kirk 维护。



  • Mysterious Trousers, LLC 和 Parker Wightman

一个使用基于块的代理而不是协议的 iOS Alert View。

安装

  1. 首选方法是通过 CocoaPods,在 Podfile 中添加 pod 'MTBlockAlertView'
  2. MTBlockAlertView.hMTBlockAlertView.mMTBlockAlertView target 中复制到您的项目中。

使用方法

不遵守 UIAlertViewDelegate 协议,而是使用块

void (^completionHandler)(UIAlertView *, NSInteger) = ^(UIAlertView *alertView, NSInteger buttonIndex) {
    if (buttonIndex == alertView.cancelButtonIndex) {
        [MTBlockAlertView showWithTitle:@"Cancel" message:@"You tapped Cancel"];
    } else {
        [MTBlockAlertView showWithTitle:@"OK" message:@"You tapped OK"];
    }
};

MTBlockAlertView *alertView = [[MTBlockAlertView alloc] initWithTitle:@"Init Version"
                                                              message:@"You tapped the init version"
                                                    completionHanlder:completionHandler
                                                    cancelButtonTitle:@"Cancel"
                                                    otherButtonTitles:@"OK", nil];

除了不必遵守协议的便利之外,您还有每个 MTBlockAlertView 实例负责其自己的消失的优点。尝试在同一个视图控制器中使用多个 UIAlertView 的代理方法的人都知道这种感觉。

我们还为常见的使用情况提供了几个类便利方法。运行 MTBlockAlertViewDemo target 以查看一些示例。

超级简单

[MTBlockAlertView showWithTitle:@"Cool Message" message:@"This is a really cool message"];

稍微控制一下

[MTBlockAlertView showWithTitle:@"Cool Message"
                        message:@"Tapping this will do something cool"
                completionBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
                    // Do some work
                }];

完整套餐

[MTBlockAlertView showWithTitle:@"Cool Message"
                        message:@"I like blocks."
              cancelButtonTitle:@"Cancel"
               otherButtonTitle:@"OK"
                 alertViewStyle:UIAlertViewStylePlainTextInput
                completionBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
                    // Do some work
                }];

贡献者

[Parker Wightman)(https://github.com/pwightman) (@parkerwightman)