【问题标题】:Difference between the following two method calls以下两种方法调用的区别
【发布时间】:2012-04-23 10:25:58
【问题描述】:
[self performSelectorOnMainThread:@selector(customFoo:) withObject:obj waitUntilDone:YES];

[self customFoo:obj];

据我所知,如果在主线程上调用第二个,那么它们两者之间没有任何区别......对吗?

它们两者之间的基本区别是什么?

【问题讨论】:

    标签: iphone objective-c selector


    【解决方案1】:

    运行时行为是相同的。但是在编译代码的时候有一个区别:第二个只有在方法customFoo:被定义的情况下才会编译。

    【讨论】:

      【解决方案2】:

      performSelector:向接收者发送指定消息并返回消息结果。

      PerformSelector 用于调用您想要执行的方法,这意味着您可以选择不同的选项来执行特定任务(方法)示例...

      – performSelector:withObject:afterDelay: // will execute method after specific delay.. 
      – performSelector:withObject:afterDelay:inModes: 
      – performSelectorOnMainThread:withObject:waitUntilDone: 
      – performSelectorOnMainThread:withObject:waitUntilDone:modes:
      – performSelector:onThread:withObject:waitUntilDone: 
      – performSelector:onThread:withObject:waitUntilDone:modes:
      

      – performSelectorInBackground:withObject: // 在后台执行任务。所以,你的 ManinThread(Application) 不会停止响应......就像多线程一样......

      直接方法 ([self customFoo:obj];) 不会提供执行任务的选择..

      For more and detailed explanation visit this reference..

      希望对你有帮助...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-12
        • 1970-01-01
        • 2018-11-12
        • 1970-01-01
        • 2016-02-02
        • 1970-01-01
        • 1970-01-01
        • 2014-09-13
        相关资源
        最近更新 更多