iOS 不带参数返回值和带参数返回值的block

带参数 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 !") ;
    }
    
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值