objective-c – 如何使用performSelector:withObject:afterDelay:与Cocoa中的原始类型?

objective-c – 如何使用performSelector:withObject:afterDelay:与Cocoa中的原始类型?,第1张

概述NSObject方法performSelector:withObject:afterDelay:允许我在一定时间后使用对象参数调用对象上的方法。它不能用于具有非对象参数的方法(例如,int,float,struct,非对象指针等)。 使用非对象参数的方法实现同样的事情的最简单的方法是什么?我知道对于常规performSelector:withObject:,解决方案是使用NSInvocation( NSObject方法performSelector:withObject:afterDelay:允许我在一定时间后使用对象参数调用对象上的方法。它不能用于具有非对象参数的方法(例如,int,float,struct,非对象指针等)。

使用非对象参数的方法实现同样的事情的最简单的方法是什么?我知道对于常规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:与Cocoa中的原始类型?全部内容,希望文章能够帮你解决objective-c – 如何使用performSelector:withObject:afterDelay:与Cocoa中的原始类型?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1049130.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存