NSObject方法performSelector:withObject:afterDelay:允许我在一段时间后使用对象参数调用对象上的方法.它不能用于带有非对象参数(例如int、float、structs、非对象指针等)的方法.

使用带有非对象参数的方法来实现同样的目标,有什么方法?我知道对于常规performSelector:withObject:,解决方案是使用NSInvocation(顺便说一句,这真的很复杂).但我不知道如何处理"延迟"部分.

谢谢

推荐答案

以下是我过go 用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相关问答推荐

如何更改 UIButton 的突出显示 colored颜色 ?

iOS UIImageView 缩小图像在 iPad 2 上产生锯齿图像

Objective C for循环中断并继续

使用 NSArray 初始化对象数组

如何创建 NSIndexPath:indexPathWithIndexes:length 所需的索引:

当我从导航控制器推送时如何隐藏导航栏?

Objective-C (cocoa) 等价于python的endswith/beginswith

在运行时判断 iOS 版本?

CF 对象与 NS 对象

进入编辑模式时动画自定义绘制的 UITableViewCell

Objective-C 中的 super 到底是什么?

Objective-C 的 NSMutableArray 是线程安全的吗?

NSCharacterSet:如何将_添加到 alphanumericCharacterSet 文本限制?

主队列上的 performSelectorOnMainThread: 和 dispatch_async() 有什么区别?

检测 UITableView 滚动

检测平移手势结束

点击手势识别器 - 哪个对象被点击了?

如何在键盘上添加完成按钮?

在 iOS 7 上运行应用程序时显示黑条(4 英寸视网膜显示屏)

如何更改标签栏上的非活动图标/文本 colored颜色 ?