NSObject
方法 performSelector:withObject:afterDelay:
允许我在一段时间后使用对象参数调用对象上的方法。它不能用于带有非对象参数的方法(例如整数、 float 、结构、非对象指针等)。
最简单的方法是用带有非对象参数的方法来实现同样的事情吗?我知道对于常规的 performSelector:withObject:
,解决方案是使用 NSInvocation
(顺便说一句,这真的很复杂)。但我不知道如何处理“延迟”部分。
谢谢,
最佳答案
这是我过去常说的使用 NSInvocation 无法更改的内容:
SEL theSelector = NSSelectorFromString(@"setOrientation:animated:");
NSInvocation *anInvocation = [NSInvocation
invocationWithMethodSignature:
[MPMoviePlayerController instanceMethodSignatureForSelector:theSelector]];
[anInvocation setSelector:theSelector];
[anInvocation setTarget:theMovie];
UIInterfaceOrientation val = UIInterfaceOrientationPortrait;
BOOL anim = NO;
[anInvocation setArgument:&val atIndex:2];
[anInvocation setArgument:&anim atIndex:3];
[anInvocation performSelector:@selector(invoke) withObject:nil afterDelay:1];
关于objective-c - 如何使用 performSelector :withObject:afterDelay: with primitive types in Cocoa?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/904515/