AlertController的Click方法封装

封装的AlertController, 不至于每次写alert时 好多Block回调;
先上 JFAlertViewController地址 https://github.com/ijunfly/JFAlertViewController

每次写AlertView时每个按钮都要写一个Block来回调方法, 这样会使代码太多

创建一个继承于JFAlertViewController的属性对象

1
@property (strong, nonatomic) JFAlertViewController *alertAllVC;

初始化时要遵循delegate和dataSource

1
2
3
4
5
6
7
8
9
#pragma mark - getting
- (JFAlertViewController *)alertAllVC {
if (!_alertAllVC) {
_alertAllVC = [JFAlertViewController alertControllerWithTitle:@"我是标题" message:@"我是消息, 消息内容的消息..." preferredStyle:UIAlertControllerStyleAlert];
_alertAllVC.delegate = self;
_alertAllVC.dataSource = self;
}
return _alertAllVC;
}

然后就可以写dataSource和delegate方法了

1
2
3
4
5
6
7
//返回选项的个数 (cancel按钮不计算在内)
- (NSUInteger)numberOfIndexsInJFAlertView:(JFAlertViewController *)alertView;
//返回选项的title
- (NSString *)JFAlertView:(JFAlertViewController *)alertView titleAtIndexNumber:(NSUInteger)index;
@optional
//返回cancel按钮title, 默认是:"取消"
- (NSString *)cancelButtonTitleInJFAlertView:(JFAlertViewController *)alertView;
1
2
3
4
5
// 选项的点击事件
- (void)JFAlertView:(JFAlertViewController *)alertView clickedAtIndex:(NSUInteger)index;

//cancel按钮的点击事件
- (void)JFAlertViewCancel:(JFAlertViewController *)alertView;

欢迎指正…

demo改天再传….

文章目录