iOS 中 Block实现UIAlertView

来源:互联网 发布:淘宝网平板电脑价格 编辑:程序博客网 时间:2024/06/06 03:05

#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


0 0
原创粉丝点击