objective-c - 如何使用 performSelector :withObject:aft

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/

相关文章:

objective-c - 数字后的 "f"

objective-c - ViewController 响应选择器 : message sent

objective-c - 无法使用 nil 模型创建 NSPersistentStoreCoord

objective-c - 如何在 Xcode 中定义预处理器符号

objective-c - 在Objective-C中将一个类的实例转换为@protocol

iphone - 如何拦截点击 UITextView 中的链接?

objective-c - Swift 变量是原子的吗?

iphone - Xcode 调试器 : view value of variable

objective-c - 按名称创建objective-c类实例?

ios - 获取当前页面