計時定時器
設計計時定時器的步驟:
1,創建可變數組,存放 0~100 的數字
2,用for循環創建 0~100 的數字,并將其放入可變數組中
3,創建定時器:創建定時器: 參數1:設置時間間隔;參數2:目標;參數3:定時器綁定的方法;參數4:補充信息,一般為空;參數5:是否重復
_timer = [NSTimerscheduledTimerWithTimeInterval:0.1target:self selector:@selector(outPut) userInfo:nilrepeats:YES];
4,計時器停止方法:if語句判斷定時器是否為空
if (_timer != nil)
5,讀取數據方法:創建靜態變量,利用索引讀取數據
static int count =0;
NSString * str =[_array objectAtIndex:count];
NSLog(@"-----%@",str);
count ++;
6,防止數組越界
if (count>99) {
count=0;
}
7,定時器銷毀
[_timer invalidate];



新聞熱點
疑難解答