[置顶] ios 时间定时器 NSTimer应用demo

时间:2021-10-16 11:07:47

原创文章,转载请注明出处:http://blog.csdn.net/donny_zhang/article/details/9251917

demo功能:ios NSTimer应用demo 。iphone6.1 测试通过。

demo说明: ios中的时间定时器 NSTimer,他用来完成程序的定时功能,他需要三个主要的参数:时间间隔NSTimeInterval浮点型,事件代理delegate和事件处理方法@selector();本例用NSTimer来取消一个程序弹出的对话框。

demo截屏:

[置顶] ios 时间定时器 NSTimer应用demo  [置顶] ios 时间定时器 NSTimer应用demo


demo主要代码:

- (void) performDismiss: (NSTimer *)timer
{
//定时器调用的处理方法,作用是隐藏提示框
[baseAlert dismissWithClickedButtonIndex:0 animated:NO];
[baseAlert release];
baseAlert = NULL;
} - (void) presentSheet
{
//定义提示框信息
baseAlert = [[UIAlertView alloc]
initWithTitle:@"Alert" message:@"\nMessage to user with asynchronous information"
delegate:self cancelButtonTitle:nil
otherButtonTitles: nil]; //初始化一个定时器,三个主要参数是,时间间隔NSTimeInterval浮点型,事件代理 delegate和事件处理方法@selector()
[NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector: @selector(performDismiss:)
userInfo:nil repeats:NO];
//显示提示框
[baseAlert show];
}


demo下载地址:

http://download.csdn.net/detail/donny_zhang/5724197