demo功能:ios NSTimer應用demo 。iphone6.1 測試通過。
demo說明: ios中的時間定時器 NSTimer,他用來完成程序的定時功能,他需要三個主要的參數:時間間隔NSTimeInterval浮點型,事件代理delegate和事件處理方法@selector();本例用NSTimer來取消一個程序彈出的對話框。
demo截屏:
demo主要代碼:
<STRONG xmlns="http://www.w3.org/1999/xhtml">- (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];
}
</STRONG>