-(void)DataShow
{
for(k=1;k<=10;k++)
{
Timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self
selector:@selector(LabelUpdateOfTimer) userInfo:nil
repeats:YES];
if(k>=10)
{
break;
}
}
[Timer invalidate];
Timer=nil;
}
-(void)LabelUpdateOfTimer
{
NSString *temp;
j=j-0.1;
temp=[[NSString alloc]initWithFormat:@" %f",j];
TimerLabel.text=temp;
}
在這裏,我創建了一個計時器,當它執行10次,我想停止計時器,但它不停止它仍然繼續。NSTimer無效不會停止計時器
你實際上正在創建10個定時器。 – sbooth 2015-02-09 13:05:30