首页 > 其他 > 详细

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

时间:2014-10-23 10:38:51      阅读:273      评论:0      收藏:0      [点我收藏+]

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];
}

 

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

原文:http://www.cnblogs.com/shaohuaios/p/4045172.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!