如何添加一个自动消失的UIAlertView

UIAlertView的消失其实是触发了一个dismiss事件,注意removefromSubview是行不通的,我们可以通过代码摸你点击了某个按钮来让UIAlertView自动消失.

通过设置一个定时器,可以设置多少秒之后自动消失.

代码实现:

- (void)popAlertView
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"恭喜,注册成功" delegate:self cancelButtonTitle:nil otherButtonTitles:@"取消", nil];
    self.alertView = alertView;

    //设置定时器,1.5秒后自动消失.
    [NSTimer scheduledTimerWithTimeInterval:1.5f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];
    [alertView show];
}


-(void)performDismiss:(NSTimer *)timer
{
    [self.alertView dismissWithClickedButtonIndex:0 animated:NO];
}

 

posted @ 2014-10-23 10:30  对酒狂歌吃馍  阅读(221)  评论(0编辑  收藏  举报