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,两个互不影响

本文介绍了iOS开发中弹窗的两种处理方式:单例模式用于仅需展示一次的场景,确保同一实例的唯一性;普通封装则适用于需要多次且数据不同的提示情况。通过具体实现代码展示了如何在iOS应用中合理运用这两种方法。
5382

被折叠的 条评论
为什么被折叠?



