1. 程式人生 > >iOS 倒計時的一種實現

iOS 倒計時的一種實現

1、view

[self performSelectorInBackground:@selector(thread) withObject:nil];
- (void)thread
{
    for(int i=300;i>=0;i--)
    {
        _count = i;
        // 回撥主執行緒
        [self performSelectorOnMainThread:@selector(mainThread) withObject:nil waitUntilDone:YES];
        sleep(1);
    }
}

// 此函式主執行緒執行
- (void)mainThread { self.time.text=[NSString stringWithFormat:@"%d",_count]; if (_count==0) { } }