IOS8.0之前使用UIAlertView作为系统默认的弹出提示框,IOS8.0后使用UIAlertController替代。相比较UIAlertController功能确实强大,多很多,包括集成了UIActionSheet的功能。但是还是比较喜欢使用UIAlertView,因为使用简单,轻量级,不用使用pushViewController来显示。
UIAlertView默认情况下,点击上面的按钮后,UIAlertView会消失;在某些特殊情况比如,强制更新,需要即便是点击的按钮,UIAlertView也不要消失。我们可以重写UIAlertView的dismissWithClickedButtonIndex方法实现该功能:
#import <UIKit/UIKit.h>
@interface CustomAlertView : UIAlertView
@property(nonatomic, assign) BOOL isClickDismiss;
@end
#import "CustomAlertView.h"
@implementation CustomAlertView
-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated{
if(!_isClickDismiss){
return;
}
[super dismissWithClickedButtonIndex:buttonIndex animated:animated];
}
@end
可以直接根据传递的属性isClickDismiss控制点击按钮后是否消失功能UIAlertController
UIAlertController