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
| - (NSUInteger)numberOfIndexsInJFAlertView:(JFAlertViewController *)alertView;
- (NSString *)JFAlertView:(JFAlertViewController *)alertView titleAtIndexNumber:(NSUInteger)index; @optional
- (NSString *)cancelButtonTitleInJFAlertView:(JFAlertViewController *)alertView;
|
1 2 3 4 5
| - (void)JFAlertView:(JFAlertViewController *)alertView clickedAtIndex:(NSUInteger)index;
- (void)JFAlertViewCancel:(JFAlertViewController *)alertView;
|
欢迎指正…
demo改天再传….