作者Dannier (猫尾巴~)
看板MacDev
标题Re: [问题] 请问Cocoa程式要如何一直做同件事情?
时间Sun May 11 09:17:23 2008
不好意思小弟不才
研究了一下了解了一些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
1F:→ Dannier:再请问一下,我ㄧ定要新开一个thread吗? 05/11 09:59