定时器NSTime用法

 //一个可以自动关闭的Alert窗口
 
    UIAlertView*alert = [[UIAlertView alloc] initWithTitle:nil
                                                    message:[@"一个可以自动关闭的Alert窗口"
                                                   delegate:nil
                                          cancelButtonTitle:nil//NSLocalizedString(@"OK",@"OK")   //取消任何按钮
                                          otherButtonTitles:nil];
    //[alertsetBounds:CGRectMake(alert.bounds.origin.x, alert.bounds.origin.y,alert.bounds.size.width,alert.bounds.size.height+30.0)];
    [alertshow];
 
    UIActivityIndicatorView*indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
 
    //Adjust the indicator so it is up a few pixels from the bottom ofthe alert
    indicator.center= CGPointMake(alert.bounds.size.width/2, alert.bounds.size.height-40.0);
    [indicatorstartAnimating];
    [alertinsertSubview:indicator atIndex:0];
    [indicatorrelease];
 
    [NSTimerscheduledTimerWithTimeInterval:3.0f
                                     target:self
                                   selector:@selector(dismissAlert:)
                                   userInfo:[NSDictionarydictionaryWithObjectsAndKeys:alert, @"alert", @"testing ", @"key",nil]  //如果不用传递参数,那么可以将此项设置为nil.
                                    repeats:NO];
 
    NSLog(@"releasealert");
    [alertrelease];
 
-(void)dismissAlert:(NSTimer *)timer{
 
    NSLog(@"releasetimer");
    NSLog([[timeruserInfo]  objectForKey:@"key"]);
 
    UIAlertView*alert = [[timer userInfo] objectForKey:@"alert"];
    [alertdismissWithClickedButtonIndex:0 animated:YES];
 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值