當(dāng)NSTimer的回調(diào)函數(shù)被調(diào)用的時(shí)候,程序是創(chuàng)建一個(gè)新的線程嗎?我寫了以下一段測(cè)試代碼,可是回調(diào)函數(shù)一直無法被觸發(fā):- (void)updateInterface:(id)sender{ a=[a stringByAppendingString:@"add string\n"]; [myTextView setStringValue:a]; return; }- (IBAction)getButtonPushed:(id)sender { NSTimer* renderTimer = [[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateInterface:) userInfo:nil repeats:YES]retain]; while(1){}}在調(diào)試的時(shí)候,程序走到while(1){}就無限制循環(huán)。而Timer卻永遠(yuǎn)沒有被觸發(fā),就是說updateInterface函數(shù)一直沒有被調(diào)用。當(dāng)我把while(1){}這行注銷掉,Timer就會(huì)被觸發(fā),觸發(fā)的時(shí)間是在getButtonPushed函數(shù)結(jié)束后。
是不是就是說,只要?jiǎng)?chuàng)建Timer的線程不結(jié)束,Timer就不會(huì)被觸發(fā)呢?求指教
慕田峪9158850
2022-06-15 11:07:14