如何使用nativeC类型与performSelectorOnMainThread:? [英] How to use native C types with performSelectorOnMainThread:?
问题描述
我想使用 performSelectorOnMainThread:
调用(void)setDoubleValue:(double)value
p>
我认为会工作的是:
NSNumber * progress = numberWithDouble:50.0];
[progressIndicator performSelectorOnMainThread:@selector(setDoubleValue :)
withObject:progress
waitUntilDone:NO];
无法使用。
然后我实现了一个辅助方法:
- (void)updateProgressIndicator:(NSNumber *)progress
{
[progressIndicator setDoubleValue:[progress doubleValue]];
}
p> 之后,我尝试使用 此解决方案适用,但它使用了大量代码,速度相当慢。 (即使我存储调用。) 有其他方法吗? 如果你在Snow Leopard,你可以使用Blocks: I'd like to call What I thought would work is: Didn't work. Then I implemented a helper method: Works, but not really clean. After that I tried it with This solution works, but it uses a lot of code and is quite slow. (Even if I store the invocation.) Is there any other way? If you are on Snow Leopard, you can use Blocks:
这篇关于如何使用nativeC类型与performSelectorOnMainThread:?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
NSInvocation
。
NSInvocation * setDoubleInvocation ;;
SEL selector = @selector(setDoubleValue :);
NSMethodSignature * signature;
signature = [progressIndicator methodSignatureForSelector:selector];
setDoubleInvocation = [NSInvocation invocationWithMethodSignature:signature];
[setDoubleInvocation setSelector:selector];
[setDoubleInvocation setTarget:progressIndicator];
double progress = 50.0;
[setDoubleInvocation setArgument:& progress atIndex:2];
[setDoubleInvocation performSelectorOnMainThread:@selector(invoke)
withObject:nil
waitUntilDone:NO];
dispatch_async(dispatch_get_main_queue ,^ {
[progressIndicator setDoubleValue:50.0];
});
(void)setDoubleValue:(double)value
using performSelectorOnMainThread:
.NSNumber *progress = [NSNumber numberWithDouble:50.0];
[progressIndicator performSelectorOnMainThread:@selector(setDoubleValue:)
withObject:progress
waitUntilDone:NO];
- (void)updateProgressIndicator:(NSNumber *)progress
{
[progressIndicator setDoubleValue:[progress doubleValue]];
}
NSInvocation
.NSInvocation *setDoubleInvocation;;
SEL selector = @selector(setDoubleValue:);
NSMethodSignature *signature;
signature = [progressIndicator methodSignatureForSelector:selector];
setDoubleInvocation = [NSInvocation invocationWithMethodSignature:signature];
[setDoubleInvocation setSelector:selector];
[setDoubleInvocation setTarget:progressIndicator];
double progress = 50.0;
[setDoubleInvocation setArgument:&progress atIndex:2];
[setDoubleInvocation performSelectorOnMainThread:@selector(invoke)
withObject:nil
waitUntilDone:NO];
dispatch_async(dispatch_get_main_queue(), ^{
[progressIndicator setDoubleValue: 50.0];
});