NSThread 的问题
我有一个问题;在我的程序中,如果我调用 2 次
[self PerformSelectorOnMainThread:@selector(callDectectionMove:) withObject:[NSNumber numberWithInt:(int)i] waitUntilDone:false];
我是否创建了 2 个线程? 因为在我的程序中我不确定是否创建 2 个线程。
谢谢
-(void)callDectectionMove:(NSNumber*)arrayIndex{
NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] init];
[myDictionary setObject:arrayIndex forKey:@"arrayIndex"];
identificationMove *identifier = [[identificationMove alloc]init];
[identifier setArrayIndex:(NSNumber*)arrayIndex];
[identifier detectionMove];
[identifier release];
}
-(void)detectPositionMovement{
for(int i = 0; i< [self.arrayMovement count]; i++){
if((actualAccelerometerX+sensibilityMovement) > [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueX] && (actualAccelerometerX-sensibilityMovement) < [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueX] &&
(actualAccelerometerY+sensibilityMovement) > [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueY] && (actualAccelerometerY-sensibilityMovement) < [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueY] &&
(actualAccelerometerZ+sensibilityMovement) > [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueZ] && (actualAccelerometerZ-sensibilityMovement) < [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueZ])
[self performSelectorOnMainThread:@selector(callDectectionMove:) withObject:[NSNumber numberWithInt:(int)i] waitUntilDone:false];
}
}
I have a question; in my program if i call 2 times
[self performSelectorOnMainThread:@selector(callDectectionMove:) withObject:[NSNumber numberWithInt:(int)i] waitUntilDone:false];
I create 2 thread or not?
Because in my program i'm not sure to create 2 threads.
Thanks
-(void)callDectectionMove:(NSNumber*)arrayIndex{
NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] init];
[myDictionary setObject:arrayIndex forKey:@"arrayIndex"];
identificationMove *identifier = [[identificationMove alloc]init];
[identifier setArrayIndex:(NSNumber*)arrayIndex];
[identifier detectionMove];
[identifier release];
}
-(void)detectPositionMovement{
for(int i = 0; i< [self.arrayMovement count]; i++){
if((actualAccelerometerX+sensibilityMovement) > [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueX] && (actualAccelerometerX-sensibilityMovement) < [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueX] &&
(actualAccelerometerY+sensibilityMovement) > [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueY] && (actualAccelerometerY-sensibilityMovement) < [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueY] &&
(actualAccelerometerZ+sensibilityMovement) > [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueZ] && (actualAccelerometerZ-sensibilityMovement) < [[[[self.arrayMovement objectAtIndex:i] arrayPositionMove]objectAtIndex:0] valueZ])
[self performSelectorOnMainThread:@selector(callDectectionMove:) withObject:[NSNumber numberWithInt:(int)i] waitUntilDone:false];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
performSelectorOnMainThread 方法不会创建新线程,它只会在主线程上分派选择器。创建新线程使用
detachNewThreadSelector:toTarget:withObject:
The method
performSelectorOnMainThread
won't create new thread it just dispatches selector on main thread. to create new thread usedetachNewThreadSelector:toTarget:withObject: