带参数 block
typedef void (^DeviceEditorCallBlock)(NSInteger edIndex , BOOL isSelect);
typedef void (^DeviceRunCallBlock)(NSInteger runIndex);
NS_ASSUME_NONNULL_BEGIN
@interface DeviceCtrlCell : UITableViewCell
@property(nonatomic,copy)DeviceEditorCallBlock deviceeditorCallBlock;
@property(nonatomic,copy)DeviceRunCallBlock deviceRunCallBlock;
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle: style reuseIdentifier:reuseIdentifier];
if (self) {
UIView *deviceCtrlView = InsertView(self.contentView, CGRectMake(0, 0, kScreenWidth, 49), kRMBColor);
self.editorBtn = InsertTitleButton(deviceCtrlView, CGRectMake(20, 10, 80, 30), 0, NSLocalizedString(@"bianjichengxu", nil), self, @selector(editorOrSaveActon:));
self.editorBtn.layer.cornerRadius = 10;
self.editorBtn.backgroundColor = [UIColor colorWithRed:85/256.0 green:176/256.0 blue:221/256.0 alpha:1.0];
self.customLabel = InsertLabel(deviceCtrlView, CGRectMake(80+15, 10, 160, 30), NSTextAlignmentCenter, NSLocalizedString(@"zidingyidianijyunxing", nil), [UIFont systemFontOfSize:15.0], kBlackColor, NO);
self.runBtn = InsertTitleButton(deviceCtrlView, CGRectMake(kScreenWidth-90, 10, 80, 30), 0, NSLocalizedString(@"shanchuchengxu", nil), self, @selector(runPrograssActon:));
self.runBtn.layer.cornerRadius = 10;
self.runBtn.backgroundColor = [UIColor colorWithRed:85/256.0 green:176/256.0 blue:221/256.0 alpha:1.0];
InsertView(deviceCtrlView, CGRectMake(0, 49, kScreenWidth, 1), kGrayColor);
}
return self;
}
#pragma mark --ActionMethod
-(void)editorOrSaveActon:(UIButton *)editorBtn{
editorBtn.selected = !editorBtn.selected;
if (editorBtn.selected) {
editorBtn.selected = YES;
if (_deviceeditorCallBlock) {
self.deviceeditorCallBlock(editorBtn.tag,editorBtn.selected);
}
}else{
editorBtn.selected = NO;
if (_deviceeditorCallBlock) {
self.deviceeditorCallBlock(editorBtn.tag,editorBtn.selected);
}
}
}
bu带参数的block
typedef void(^alertMessageCallback)(void);
typedef void (^CustomCallBlock)(NSString *name);
+ (void)showAlertMessageWithContent:(NSString *)title contentMessage:(NSString *)contentMessage cancelTitle:(NSString *)cancelTitle cancelCallBack:(alertMessageCallback)cancel sureTitle:(NSString *)sureTitle sureCallBack:(void (^)(NSString * text))sure
{
NSAssert(cancelTitle.length, @"you should add a suretitle and sureCallback");
__block NSString *nameText;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:contentMessage preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
dispatch_after(0.2, dispatch_get_main_queue(), ^{
if (cancel) cancel() ;
[alertController dismissViewControllerAnimated:YES completion:nil];
});
}];
if (sureTitle.length) {
UIAlertAction *action = [UIAlertAction actionWithTitle:sureTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
dispatch_after(0.2, dispatch_get_main_queue(), ^{
UITextField *textField = alertController.textFields.firstObject;
if (sure) sure(textField.text) ;
[alertController dismissViewControllerAnimated:YES completion:nil];
});
}];
[alertController addAction:action];
}
[alertController addAction:action2];
[[EasyUtils topViewController] presentViewController:alertController animated:YES completion:nil];
}
else{
NSAssert(NO, @"UIAlertController can't support !") ;
}
}