#import "MKAlertView.h"
#import <objc/runtime.h>
staticconstNSString *UIALERTVIEW_CLICKED_KEY =@"UIAlertView_Clicked_Key";
@implementation MKAlertView
//代理并实现alertView代理方法
- (void)handlerClickedButton:(void (^)(NSInteger btnIndex))alertBlock{
self.delegate =self;
objc_setAssociatedObject(self, &UIALERTVIEW_CLICKED_KEY, alertBlock,OBJC_ASSOCIATION_COPY);
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
void (^block)(NSInteger btnIndex) =objc_getAssociatedObject(self, &UIALERTVIEW_CLICKED_KEY);
if (block) block(buttonIndex);
}
@end
iOS 中 Block实现UIAlertView
最新推荐文章于 2018-04-25 21:56:50 发布