逻辑复杂的业务代码如何实现有顺序的跳转展示(登录成功后要去摇奖,设置预留信息,修改密码,弹窗警告......等等)

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/qq_15509071/article/details/73647780

在登录成功后要展示预留信息,要判断有木有摇奖(如果没有摇奖权限或在摇奖页面点的取消),判断是不是黑名单账户(不是黑名单,黑名单信息展示完成后),有木有开通手机银行,是否需要强制设置预留信息,是否强制修改简单密码,是否提示推送弹框,是否展示手势弹框。有的需要view的展示,有的需要控制器的推入,有的需要警告框,点警告框跳控制器。推送的警告框如果没展示要直接展示手势的警告框,如果推送的警告框展示但点击的是上面的取消按钮,也要展示手势的。 这一大堆流程已经让人头疼。如何使其顺序执行也很复杂。在这里使用封闭判断每个逻辑然后暴露出block接口,继续走下面的流程。

我们拿三个来举例:摇奖(包含取消按钮),强制预留信息(直接进vc),手势弹框

1.将这三个元素,不管是页面还是弹框都定义为一个NSObject

//
//  ElementObject.h
//  UniversalJumpDemo
//
//  Created by yfc on 2017/6/23.
//  Copyright © 2017年 yfc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef void(^PublicBlock)(id result);

@interface ElementObject : NSObject
- (instancetype)initWithController:(UIViewController*)controller parameterOne:(NSString *)parameterOne parameterTwo:(NSString *)parameterTwo block:(PublicBlock)block;
- (void)toRemoveWaring;

@end
//
//  ElementObject.m
//  UniversalJumpDemo
//
//  Created by yfc on 2017/6/23.
//  Copyright © 2017年 yfc. All rights reserved.
//

#import "ElementObject.h"
#import <Foundation/Foundation.h>

@implementation ElementObject
- (instancetype)initWithController:(UIViewController*)controller parameterOne:(NSString *)parameterOne parameterTwo:(NSString *)parameterTwo block:(PublicBlock)block;{
    self = [super init];
    if (self) {
        
        
    }
    
    return self;

}
- (void)toRemoveWaring;{
    
}
@end

2在initWithController:parameterOne:parameterTwo:block:这个方法里再具体判断


为简便起见parameterOne用来表示不同的Element,parameterTwo表示需要的参数
 

关键代码

- (void)btnClicked:(UIButton *)btnn{

    //
    //我们拿三个来举例:摇奖(包含取消按钮),强制预留信息(直接进vc),手势弹框
    //
    NSString *isDrawLottery = @"YES";//是否摇奖
    NSString *mustSetTip = @"YES";//是否强制设置信息
    NSString *isShowAlertView = @"YES";//是否展示弹框
    
    //第一步 判断摇奖
    ElementObject *drawLotteryObj = [[ElementObject alloc]initWithController:self parameterOne:@"DrawLottery" parameterTwo:isDrawLottery block:^(id result) {
        //第二步 判断预留信息
        ElementObject *mustSetTipObj = [[ElementObject alloc]initWithController:self parameterOne:@"SetTip" parameterTwo:mustSetTip block:^(id result) {
            //第三步 判断弹框
            ElementObject *showAlertViewObj = [[ElementObject alloc]initWithController:self parameterOne:@"isShowAlertView" parameterTwo:isShowAlertView block:^(id result) {
                
                
            }];
            [showAlertViewObj toRemoveWaring];
        }];
        [mustSetTipObj toRemoveWaring];
    }];
    [drawLotteryObj toRemoveWaring];
    
}
        //摇奖判断
        if([parameterOne isEqualToString:@"DrawLottery"]){
            if ([parameterTwo isEqualToString:@"YES"]) {
                //结束流程去摇奖页面并且登录标记记为yes
                DrawLotteryViewController *drawLotteryViewController = [[DrawLotteryViewController alloc]init];
                [controller.navigationController pushViewController:drawLotteryViewController animated:YES];
            }else{
                block(@"");
            }
        }
        //判断预留
        else if ([parameterOne isEqualToString:@"SetTip"]){
            if ([parameterTwo isEqualToString:@"YES"]) {
                
                MustSetTipViewController *mustSetTipViewController = [[MustSetTipViewController alloc]init];
                [controller.navigationController pushViewController:mustSetTipViewController animated:YES];
                [mustSetTipViewController setBackActionBlock:^(id result) {
                    block(@"");
                }];
                
            }else{
                block(@"");
            }
        }
        //判断弹框
        else if ([parameterOne isEqualToString:@"isShowAlertView"]){
            if ([parameterTwo isEqualToString:@"YES"]) {
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"成功走完所有流程" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alertView show];
            }else{
                block(@"");
            }
        }

demo下载地址 https://github.com/XiaoHeHe1/-/tree/master

猜你喜欢

转载自blog.csdn.net/qq_15509071/article/details/73647780