嵌套block处理方式

嵌套block处理方式

- (void)pushToWalletView {
    __weak TGGroupCardTaskManager  *wTGGroupCardTaskManager = self;
    [MBProgressHUD showLoading];
    [NRUserRequest checkPayPwdComplete:^(NSError *error, BOOL sucess, BOOL hasCheck) {
      __strong  UIViewController *viewController = self.groupInfoVC;//加强指针防止self.groupInfoVC提前释放,self.groupInfoVC在manager负值就是weak引用
        if (!error) {
            [MBProgressHUD hideHUD];
            if (sucess) {
                if (!([[NRCodeCenter sharedInstance] codeCode] && [[NRCodeCenter sharedInstance] codeR])) {
                    NRVerificationCodeVC *vc = [[NRVerificationCodeVC alloc] init];
                    vc.codetype = IdentifyCodeLoginType;
                    [vc setReturnBlock:^{
                        __strong TGGroupCardTaskManager  *str1TGGroupCardTaskManager = wTGGroupCardTaskManager;//嵌套block

                        [str1TGGroupCardTaskManager pushToMyView];
                    }];
                    if (![viewController.navigationController.viewControllers.lastObject isKindOfClass:[NRVerificationCodeVC class]]) {
                        
                        [viewController presentViewController:[[NRNavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
                    }
                }else{
                    
                   __strong TGGroupCardTaskManager  *strTGGroupCardTaskManager = wTGGroupCardTaskManager;
                    //单层block
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{//加延迟 使未登录的弹窗停留 不会一闪而过
                         [strTGGroupCardTaskManager pushToMyView];
                    });
                   
                }
            } else {
                NRVerificationCodeVC *vc = [[NRVerificationCodeVC alloc] init];
                vc.codetype = IdentifyCodeRegisterType;
                [vc setReturnBlock:^{
                      __strong TGGroupCardTaskManager  *strTGGroupCardTaskManager = wTGGroupCardTaskManager;////嵌套block
                    [strTGGroupCardTaskManager pushToMyView];
                }];
                if (![viewController.navigationController.viewControllers.lastObject isKindOfClass:[NRVerificationCodeVC class]]) {
                    [viewController presentViewController:[[NRNavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
                }
            }
        } else {
            [MBProgressHUD showError:[error localizedDescription]];
        }
    }];
}

你可能感兴趣的:(ios)