标签:oid content ati log code 实现 sel self obj
#import <UIKit/UIKit.h> typedef void(^resultBlock)(void); @interface MyView : UIView //回调函数的声明 @property (assign, nonatomic)resultBlock block; //回调函数的实如今调用端实现 - (void)doSomething:(NSString *)string withTheBlock:(resultBlock)block; @end
#import "MyView.h" @implementation MyView - (void)doSomething:(NSString *)string withTheBlock:(resultBlock)block { self.block = block; NSLog(@"string:%@",string); if (self.block) { self.block(); } } @end
- (void)viewDidLoad { [super viewDidLoad]; MyView *view = [[MyView alloc]init]; [view doSomething:@"Hello" withTheBlock:^{ NSLog(@"这里是回调"); }]; }
标签:oid content ati log code 实现 sel self obj
原文地址:http://www.cnblogs.com/yutingliuyl/p/7100127.html