簡體   English   中英

NSTimer-活動順序-如何使計時器無效?

[英]NSTimer - sequence of activities - how to invalidate timer?

我想使用2個計時器進行一系列活動(A和B)。 計時器失效使我遇到一些問題...這是正確的進行方法嗎? 謝謝!!!

timerAStart = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(startActivityA) userInfo:nil repeats:NO];
timerAStop = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(StopA) userInfo:nil repeats:NO];
timerBStart = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(startActivityB) userInfo:nil repeats:NO];
timerBStop = [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(StopB) userInfo:nil repeats:NO];
- (void) StopA {
[timerAStart invalidate];
timerAStart=nil;
}
- (void) StopB {
[timerBStart invalidate];
timerBStart=nil;
}

您不需要使無效,因為您的計時器是非重復的。 如果查看文檔,您會發現非重復計時器會自動失效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM