NSThread 的问题

发布于 2024-09-11 12:49:18 字数 1721 浏览 7 评论 0原文

我有一个问题;在我的程序中,如果我调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒与心事 2024-09-18 12:49:18

performSelectorOnMainThread 方法不会创建新线程,它只会在主线程上分派选择器。创建新线程使用 detachNewThreadSelector:toTarget:withObject:

The method performSelectorOnMainThread won't create new thread it just dispatches selector on main thread. to create new thread use detachNewThreadSelector:toTarget:withObject:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文