UIAlertView 只弹一次实现
2016-10-13 本文已影响547人
NN_逝去
思路:把所有创建的alertView都存储在数组里。。。遍历保留最后一个😂
Talk is cheap. Show me the code
环信EMAlertView
EMAlertView类文件地址

MXAlertViewManager 单例的实现方式如下:
#import "MXAlertViewManager.h"
#import "EMAlertView.h"
@interface MXAlertViewManager ()
@property (nonatomic, strong) NSMutableArray *alertArray;
@end
@implementation MXAlertViewManager
+ (instancetype)sharedInstance
{
static MXAlertViewManager *_sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedManager = [[self alloc] init];
});
return _sharedManager;
}
- (instancetype)init
{
if (self == [super init]) {
_alertArray = [NSMutableArray array];
}
return self;
}
- (void)alertCount:(EMAlertView *)alertView
{
[self.alertArray addObject:alertView];
if (self.alertArray.count > 1) {
for (NSInteger i=0; i<self.alertArray.count-1; i++) {
EMAlertView *alertView = self.alertArray[i];
[alertView dismissWithClickedButtonIndex:-1 animated:YES];
}
}
}
@end```
[iOS dismiss UIAlertView beforing showing another](http://stackoverflow.com/questions/5399219/ios-dismiss-uialertview-beforing-showing-another) 从`stackoverflow`搜索的类似跟我的问题描述
或者你用`runtime`拦截`show`方法
^_^ 如果有其他更好的想法,欢迎提出,共同进步。。。