Re: [問題] 請問Cocoa程式要如何一直做同件事情?

看板MacDev作者 (貓尾巴~)時間16年前 (2008/05/11 09:17), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串3/7 (看更多)
不好意思小弟不才 研究了一下了解了一些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

05/11 09:59, , 1F
再請問一下,我ㄧ定要新開一個thread嗎?
05/11 09:59, 1F
文章代碼(AID): #189aaabC (MacDev)
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 3 之 7 篇):
文章代碼(AID): #189aaabC (MacDev)