- (void)TargetHit:(int)target{
void (^threadBlock)(void) = ^{
NSLog(@"respond to selector %d", [self respondsToSelector:@selector(changeImageOfTarget:)]);
[[NSOperationQueue mainQueue] performSelectorOnMainThread:@selector(changeImageOfTarget:) withObject:[NSNumber numberWithInt:target] waitUntilDone:YES];
[NSThread sleepForTimeInterval:1.0];
[[NSOperationQueue mainQueue] performSelectorOnMainThread:@selector(changeImageOfTarget:) withObject:[NSNumber numberWithInt:target] waitUntilDone:YES];
};
dispatch_async(dispatch_queue_create(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), threadBlock);
}
I can understand why my code returns YES
to responds to selector but when I try and perform it I get an error message and the app crashes.
[NSOperationQueue changeImageOfTarget:]: unrecognized selector sent to instance 0x6a39810'
It's also the same for
[[NSThread currentThread] performSelectorOnMainThread:@selector(changeImageOfTarget:) withObject:[NSNumber numberWithInt:target] waitUntilDone:YES];
How am I able to perform a method or @selector
on the main thread?