나는 내 코드에 문제가있다 나는 NSThread와 2 개의 다른 인스턴스를 만들고 싶다.하지만 내 문제는 이것들이 일어나지 않는다고 생각한다. 내 문제에 대한 해결책을 찾을 수 있습니까? 코드 예제를 게시 할 수 있습니까? 솔루션 예제를 보여줄 수 있습니까? 주셔서 감사합니다 코드에서NSThread와 관련된 문제
@implementation myClass
-(void)detectMove:(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)callDectectionMove:(NSNumber*)arrayIndex{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(detectMove:) withObject:(NSNumber*)arrayIndex waitUntilDone:NO];
[pool 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])
//I'm not sure that these istruction can start a 2 different and indipendent thread
[NSThread detachNewThreadSelector:@selector(callDectectionMove:) toTarget:self withObject:[NSNumber numberWithInt:(int)i]];
}
}
@end
문제를 언급하지 않았습니다. 경고/충돌/사물이 실행되지 않았습니까? 문제가 무엇입니까? 또한 왜 당신이 다른 스레드에서'callDectectionMove'를 실행하는지 이해하지 못합니다. 그 메소드에있는 모든 것이 메인 스레드에서 다른 메소드를 실행하고있을 때입니다 ... –
만약 충돌이없고 비슷하지만 if 2 시간 동안 진실하다, 프로그램은 2 개의 다른 실을 점심 먹을 수 없다. 나는 가속도계의 움직임을 인식하고 싶기 때문에이 구조를 만든다. 그리고 나는 3을위한 2 가지 다른 움직임 3을위한 2 개의 다른 스레드를 가져야 만한다 .... ok? – zp26