【发布时间】:2011-03-15 10:24:51
【问题描述】:
当我创建一个 NSThread 时,我向它传递了一个我希望进程知道的数字。我可以理解如何设置数字,但我不知道如何从线程选择器方法中读取数字,以便我可以将其传递给计时器。
你是怎么做到的?
-(void) setthread
{
//这里把数字传给选择器就好了
NSThread* timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerThread) object:[NSNumber numberWithInt:index]];/
[timerThread setThreadPriority:0.5];
[timerThread start]; //start the thread
}
// 不知道如何读取传递给这个选择器的值
-(void) startTimerThread
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
[[NSTimer scheduledTimerWithTimeInterval: 0.1
target: self
selector: @selector(timerTick:)
userInfo: thenumberhere
repeats: YES] retain];
[runLoop run];
[pool release];
}
- (void)timerTick:(NSTimer *)timer
{
//code
}
【问题讨论】:
标签: iphone cocoa ios4 nsthread