1、声明block的类型finish
typedef void(^finish)(WMCustomDatePicker *picker,NSDate *date);
2、声明一个finish类型的变量
@property (nonatomic,copy) finish finished;
3、声明一个调用finish的函数
- (id)initWithframe:(CGRect)frame PickerStyle:(WMDateStyle)WMDateStyle didSelectedDateFinish:(void(^)(WMCustomDatePicker *picker,NSDate *date))finish;
4、给finish赋值
- (id)initWithframe:(CGRect)frame PickerStyle:(WMDateStyle)WMDateStyle didSelectedDateFinish:(void(^)(WMCustomDatePicker *picker,NSDate *date))finish{
self.datePickerStyle = WMDateStyle;
self.finished = finish;
return [self initWithFrame:frame];
}
外部调用init函数
WMCustomDatePicker *endTimepicker = [[WMCustomDatePicker alloc]initWithframe:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, SCREEN_HEIGHT * 0.264) PickerStyle:WMDateStyle_YearMonthDayHourMinute didSelectedDateFinishBack:^(WMCustomDatePicker *picker, NSString *year, NSString *month, NSString *day, NSString *hour, NSString *minute, NSString *weekDay) {
_activityEndTimeTF.text = [NSString stringWithFormat:@"%@.%@.%@ %@:%@",year,month,day,hour,minute];
}];
5、调用finish
if (_finished) {
self.finished(self,_date);
}