iOS-UIAlertView弹框2秒后自动消失

代码写法如下:

#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    [selfshowAlert];    

}

/**

 *  弹框提示

 */

- (void)showAlert{

    

    UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"2秒后将消失"delegate:nil cancelButtonTitle:nilotherButtonTitles:nil];

    

    [alertshow];

    // 2秒后执行

    [selfperformSelector:@selector(dimissAlert:)withObject:alertafterDelay:2.0];

}


/**

 *  移除弹框

 */

- (void) dimissAlert:(UIAlertView *)alert {

    if(alert){

        [alert dismissWithClickedButtonIndex:[alert cancelButtonIndexanimated:YES];

    }

    

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

}


@end


运行效果如下:

iOS-UIAlertView弹框2秒后自动消失_第1张图片



你可能感兴趣的:(ios笔记)