-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIActionSheet+Blocks.m
38 lines (31 loc) · 1.18 KB
/
UIActionSheet+Blocks.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// UIActionSheet+Block.m
// WangPan
//
// Created by riven on 13-11-29.
// Copyright (c) 2013年 sohu. All rights reserved.
//
#import "UIActionSheet+Blocks.h"
#import <objc/runtime.h>
static NSString *handlerRunTimeAccosiationKey = @"ActionSheetViewBlocksDelegate";
@implementation UIActionSheet (Blocks)
- (void)showActionSheetViewFromView:(UIView *)view WithHandler:(UIActionSheetViewCallBackHandler)handler
{
objc_setAssociatedObject(self, (__bridge const void *)(handlerRunTimeAccosiationKey), handler, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self setDelegate:self];
if ([view isKindOfClass:[UITabBar class]]) {
[self showFromTabBar:(UITabBar *)view];
}else if ([view isKindOfClass:[UIToolbar class]]){
[self showFromToolbar:(UIToolbar *)view];
}else{
[self showInView:view];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIActionSheetViewCallBackHandler completionHandler = objc_getAssociatedObject(self, (__bridge const void *)(handlerRunTimeAccosiationKey));
if (completionHandler != nil) {
completionHandler(actionSheet, buttonIndex);
}
}
@end