美文网首页IOS开发路上的故事ios开发整理
UIAlertView 点击按钮后控制其是否消失

UIAlertView 点击按钮后控制其是否消失

作者: 悲酥清风__ | 来源:发表于2015-12-25 17:12 被阅读1011次

    新建NotDismissAlertView类,继承UIAlertView。

    设置控制是否消失的标示符

    重写  在-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated代理方法里判断

    具体代码如下:

    NotDismissAlertView.h:

    #import@interface NotDismissAlertView : UIAlertView

    @property(nonatomic, assign) BOOL notDisMiss;

    @end

    --------------------------------------

    NotDismissAlertView.m:

    #import "NotDismissAlertView.h"

    @implementation NotDismissAlertView

    -(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated {

    if (_notDisMiss)

    {

    return;

    }

    [super dismissWithClickedButtonIndex:buttonIndex animated:animated];

    }

    @end

    -------

    在初始化AlertView时设定其notDisMiss值即可

    NotDismissAlertView *updateAlert = [[NotDismissAlertView alloc] initWithTitle:@"新版本提示" message:[NSString stringWithFormat:@"更新日志:\\n%@",changeLog] delegate:self cancelButtonTitle:@"前往下载" otherButtonTitles:nil, nil];

    updateAlert.notDisMiss = YES;

    [updateAlert show];

    (可用于强制更新的场景)。

    相关文章

      网友评论

        本文标题:UIAlertView 点击按钮后控制其是否消失

        本文链接:https://www.haomeiwen.com/subject/cpbehttx.html