0
点赞
收藏
分享

微信扫一扫

使用第三方的支持Block 的UIAlertView

github 网址:

​​https://github.com/jivadevoe/UIAlertView-Blocks​​

使用

在Pods的Podfile里加入:

pod 'UIAlertView-Blocks', '~> 1.0'

运行命令:

pod update

代码

首先要引用

#import <UIAlertView+Blocks.h>

主体程序

RIButtonItem *cancelItem = [RIButtonItem itemWithLabel:@"No" action:^{
// this is the code that will be executed when the user taps "No"
// this is optional... if you leave the action as nil, it won't do anything
// but here, I'm showing a block just to show that you can use one if you want to.
}];

RIButtonItem *deleteItem = [RIButtonItem itemWithLabel:@"Yes" action:^{
// this is the code that will be executed when the user taps "Yes"
// delete the object in question...
[context deleteObject:theObject];
}];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Delete This Item?"
message:@"Are you sure you want to delete this really important thing?"
cancelButtonItem:cancelItem
otherButtonItems:deleteItem, nil];
[alertView show];

也可以初始化后添加按钮

[alertView addButtonItem:deleteItem];

其它问题

我在使用时,提示:
使用第三方的支持Block 的UIAlertView_初始化

ld: library not found for -lPods-UIAlertView-Blocks
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(null): Library not found for -lPods-UIAlertView-Blocks
(null): Linker command failed with exit code 1 (use -v to see invocation)

处理方法:
把项目和Pods的Architectures设置一致:
使用第三方的支持Block 的UIAlertView_pods_02

在Podfile里加入:

post_install do |installer| installer.project.targets.each do |target| target.build_configurations.each do |config| config.build_settings[‘ARCHS’] = “armv7” end end end

后来的一篇文章里可以看到目前oc原生支持的block UIAlertView用法。


举报

相关推荐

0 条评论