看板 MacDev 關於我們 聯絡資訊
不好意思小弟不才 研究了一下了解了一些NSRunLoop 可是還是有問題 我想要按一個扭開始一直做某件事情 按另一個則停止 但我還是不知道要怎麼讓它停止NSRunLoop 實在想不出辦法來 想要請教高手指點....感激不盡(躬) 我的code: #import "ConverterController.h" #import "Converter.h" @implementation ConverterController - (void)Started { NSAutoreleasePool* thePool = [[NSAutoreleasePool alloc] init]; Converter *theLauncher=[[Converter alloc] init]; NSTimer *theTimer=[theLauncher getTimer]; [theTimer retain]; NSDate* theNextDate = [NSDate distantFuture]; NSRunLoop *theRL = [NSRunLoop currentRunLoop]; [theRL addTimer: theTimer forMode:NSDefaultRunLoopMode ]; [theRL runMode:NSDefaultRunLoopMode beforeDate:theNextDate]; thePool = [[NSAutoreleasePool alloc] init]; [thePool release]; } - (IBAction)StartThread:(id)sender { [self Started ]; } - (IBAction)StopThread:(id)sender { /*這裡不知道要放什麼*/ } @end ------------------------------------------------------------------------------- #import "Converter.h" @implementation Converter - (NSTimer *)getTimer { NSTimer *theTimer; theTimer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doSomething) userInfo:nil repeats:YES]; return [theTimer autorelease]; } -(void)doSomething { NSLog(@"Do Loop!!\n"); } @end -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 210.192.174.40
Dannier:再請問一下,我ㄧ定要新開一個thread嗎? 05/11 09:59