Ios 响应选择器,但抛出错误
我可以理解为什么我的代码返回Ios 响应选择器,但抛出错误,ios,objective-c,grand-central-dispatch,nsoperationqueue,Ios,Objective C,Grand Central Dispatch,Nsoperationqueue,我可以理解为什么我的代码返回YES以响应选择器,但当我尝试执行它时,会收到错误消息,应用程序崩溃 - (void)TargetHit:(int)target{ void (^threadBlock)(void) = ^{ NSLog(@"respond to selector %d", [self respondsToSelector:@selector(changeImageOfTarget:)]); [[NSOperationQueue mainQ
YES
以响应选择器,但当我尝试执行它时,会收到错误消息,应用程序崩溃
- (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);
}
这对我来说也是一样的
[NSOperationQueue changeImageOfTarget:]: unrecognized selector sent to instance 0x6a39810'
如何在主线程上执行方法或选择器?
self
可能会响应选择器。问题是[NSOperationQueue mainQueue]
没有
如何在主线程上执行方法或@selector
只需在要执行操作的对象上调用它:
[[NSThread currentThread] performSelectorOnMainThread:@selector(changeImageOfTarget:) withObject:[NSNumber numberWithInt:target] waitUntilDone:YES];
self
可能响应选择器。问题是[NSOperationQueue mainQueue]
没有
如何在主线程上执行方法或@selector
只需在要执行操作的对象上调用它:
[[NSThread currentThread] performSelectorOnMainThread:@selector(changeImageOfTarget:) withObject:[NSNumber numberWithInt:target] waitUntilDone:YES];