十九,iOS对类似alertView弹框进行单例的应用避免在网络请求时重复信息的弹出

来源:互联网 发布:中科软件 编辑:程序博客网 时间:2024/05/22 16:42


1,首先是对所有的弹窗的类型进行判断是不是只需要弹一次就好了如果只需要弹一次就使用单例的方法来使用

首先声明定义使用单例来处理:

+(AlertView *)sharedInstance;

+(AlertView *)sharedInstance{
    static AlertView *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        sharedInstance -> _alertArray = [NSMutableArray array];
        [sharedInstance setIsShareInstance:YES];
    });
    return sharedInstance;
}

这样的话这个弹框只会弹最后一个;


2,弹框信息不同需要不重复的数据给用户弹框提醒,则使用正常的封装方法来使用

#import "AlertView.h"

@property (nonatomic ,strong) AlertView *alert;

    _alert = [[AlertView alloc]init];
使用方法

 [_alert showTitle:@"1234" message:@"是否取消" buttonTitle:@"取消" buttonBlock:^{
        NSLog(@"1234");
    } otherTitle:@"确定" otherBolck:^{

        [_alert hide];
        
        NSLog(@"123445yuuu");

    }];

3,两个互不影响

4,地址如下

https://github.com/wang6177ming123/alertSingleton

1 0