iOS: performSelectorOnMainThread(译)
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
performSelectorOnMainThread:withObject:waitUntilDone:
基于默认模式调用主线程中接收器的方法
Invokes a method of the receiver on the main thread using the default mode.
参数 Parameters
aSelector
一个选择器, 指定要调用的方法。该方法不应该有明确的返回值并且最多只有一个id类型的参数,或者没有参数。
A selector that identifies the method to invoke. The method should not have a significant return value and should take a single argument of type id, or no arguments.
arg
需要传递给调用方法的参数. 如果没有需要的参数,传入nil
The argument to pass to the method when it is invoked. Pass nil if the method does not take an argument.
wait
一个布尔值,指定是否阻塞当前线程直到指定选择器在主线程中执行完毕。选择YES会阻塞这个线程;选择NO,本方法会立刻返回。
A Boolean that specifies whether the current thread blocks until after the specified selector is performed on the receiver on the main thread. Specify YES to block this thread; otherwise, specify NO to have this method return immediately.
如果当前线程也是主线程,选择YES,消息会立即派发,处理。
If the current thread is also the main thread, and you specify YES for this parameter, the message is delivered and processed immediately.
讨论 Discussion
你可以使用本方法向主线程发送消息. 主线程包含应用程序的主循环(这是NSApplication接收事件的地方). 在这种情况下, 消息相当于是你想要在线程上执行的当前对象的方法.
You can use this method to deliver messages to the main thread of your application. The main thread encompasses the application’s main run loop, and is where the NSApplication object receives events. The message in this case is a method of the current object that you want to execute on the thread.
本方法使用Common模式将消息加入到主线程运行循环(run loop)队列, 即 与NSRunLoopCommonModes常数相关的模式。作为其正常运行循环处理的一部分,主线程从队列中取出消息(假设它是在Common模式中运行)并调用所需的方法。在同一个线程多次调用此方法会导致相应的选择进行排队,再按相同的顺序取出执行。
This method queues the message on the run loop of the main thread using the common run loop modes—that is, the modes associated with the NSRunLoopCommonModes constant. As part of its normal run loop processing, the main thread dequeues the message (assuming it is running in one of the common run loop modes) and invokes the desired method. Multiple calls to this method from the same thread cause the corresponding selectors to be queued and performed in the same same order in which the calls were made.
你不能取消由本方法加入队列的消息. 如果你想取消当前线程的一条消息, 必须使用
performSelector:withObject:afterDelay: 或
performSelector:withObject:afterDelay:inModes: 方法.
You cannot cancel messages queued using this method. If you want the option of canceling a message on the current thread, you must use either the
performSelector:withObject:afterDelay: or
performSelector:withObject:afterDelay:inModes: method.
特别注意事项
Special Considerations
本方法在runloop中注册当前上下文, 并且依赖于runloop定期运行以保证正确执行. ?????。如果你在运行一个调度队列时需要这种类型的功能, 你应该使用dispatch_after和相关的方法来得到你想要的行为。
This method registers with the runloop of its current context, and depends on that runloop being run on a regular basis to perform correctly. One common context where you might call this method and end up registering with a runloop that is not automatically run on a regular basis is when being invoked by a dispatch queue. If you need this type of functionality when running on a dispatch queue, you should use dispatch_after and related methods to get the behavior you want.
iOS: performSelectorOnMainThread(译)的更多相关文章
- Swift高仿iOS网易云音乐Moya+RxSwift+Kingfisher+MVC+MVVM
效果 列文章目录 因为目录比较多,每次更新这里比较麻烦,所以推荐点击到主页,然后查看iOS Swift云音乐专栏. 目简介 这是一个使用Swift(还有OC版本)语言,从0开发一个iOS平台,接近企业 ...
- OC高仿iOS网易云音乐AFNetworking+SDWebImage+MJRefresh+MVC+MVVM
效果 因为OC版本大部分截图和Swift版本一样,所以就不再另外截图了. 列文章目录 因为目录比较多,每次更新这里比较麻烦,所以推荐点击到主页,然后查看iOS云音乐专栏. 目简介 这是一个使用OC语言 ...
- Xcode8 及iOS10适配问题汇总
上点干货,目前得知的一些bug解决汇总:iOS10相册相机闪退bughttp://www.jianshu.com/p/5085430b029fiOS 10 因苹果健康导致闪退 crashhttp:// ...
- Model-View-ViewModel for iOS [译]
如果你已经开发一段时间的iOS应用,你一定听说过Model-View-Controller, 即MVC.MVC是构建iOS app的标准模式.然而,最近我已经越来越厌倦MVC的一些缺点.在本文,我将重 ...
- (译)iOS Code Signing: 解惑
子龙山人 Learning,Sharing,Improving! (译)iOS Code Signing: 解惑 免责申明(必读!):本博客提供的所有教程的翻译原稿均来自于互联网,仅供学习交流之用,切 ...
- iOS: 学习笔记, 使用performSelectorOnMainThread及时刷新UIImageView
在iOS中, 界面刷新在主线程中进行, 这导致NSURLSession远程下载图片使用UIImageView直接设置Image并不能及时刷新界面. 下面的代码演示了如何使用 performSelect ...
- 【译】iOS人性化界面指南(iOS Human Interface Guidelines)(一)
1. 引言1.1 译者自述 我是一个表达能力一般的开发员,不管是书面表达,还是语言表达.在很早以前其实就有通过写博客锻炼这方面能力的想法,但水平有限实在没有什么拿得出手的东西分享.自2015年7月以来 ...
- iOS APP之本地数据存储(译)
最近工作中完成了项目的用户信息本地存储,查阅了一些本地存储加密方法等相关资料.期间发现了一个来自印度理工学院(IIT)的信息安全工程师的个人博客,写了大量有关iOS Application secur ...
- iOS 9,为前端世界都带来了些什么?「译」 - 高棋的博客
2015 年 9 月,Apple 重磅发布了全新的 iPhone 6s/6s Plus.iPad Pro 与全新的操作系统 watchOS 2 与 tvOS 9(是的,这货居然是第 9 版),加上已经 ...
随机推荐
- oracle Imp和exp以及导入常见的错误
一 1) 数据库对象已经存在 一般情况, 导入数据前应该彻底删除目标数据下的表, 序列, 函数/过程,触发器等; 数据库对象已经存在, 按缺省的imp参数, 则会导入失败 如果用了参数ignore=y ...
- 【python自动化第六篇:面向对象】
知识点概览: 面向对象的介绍 面向对象的特性(class,object)实例变量,类变量 面型对象编程的介绍 其他概念 一.面向对象介绍 编程范式:面向对象,面向过程,函数式编程 面向过程:通过一组指 ...
- Android开发之点九图的制作说明
总结: 左边的点代表垂直拉伸的区域, 上边的点代表水平拉伸的区域. 右边的点代表文字等的垂直可可显示区域. 下边的点代表文字等的水平可显示区域. 左上重合的区域就是拉伸区域. 右下重合的区域就是显示区 ...
- Robotium---环境搭建及入门示例
Robotium是一款基于控件的Android自动化测试框架 环境搭建(window): 安装JDK以及集成Android Sdk的eclipise. 入门: 1,下载Robotium Solo 5. ...
- Hadoop-2.4.1学习之Map任务源代码分析(下)
在Map任务源码分析(上)中,对MAP阶段的代码进行了学习,这篇文章文章将学习Map任务的SORT阶段.假设Reducer的数量不为0.则还须要进行SORT阶段.但从上面的学习中并未发现与MAP阶段运 ...
- linux中创建静态库和动态库
1. 函数库有两种:静态库和动态库. 静态库在程序编译的时候会被连接到目标代码中,程序运行时将不再需要改静态库. 动态库中程序编译的时候并不会连接到目标代码中,而是在程序运行时才被载入,因此在程序运行 ...
- [置顶] String StringBuffer StringBuilder的区别剖析
这是一道很常见的面试题目,至少我遇到过String/StringBuffer/StringBuilder的区别:String是不可变的对象(final)类型,每一次对String对象的更改均是生成一个 ...
- expect批量分发公钥
sshkey.exp #!/usr/bin/expect# 由于是多台服务器,需要在shell脚本中循环调用该脚本 if { $argc != 2 } { send_user "usage: ...
- CentOS 6.7 安装配置BT下载工具Transmission
1.配置额外yum源 i386 cd /etc/yum.repos.d/ wget http://geekery.altervista.org/geekery-el6-i686.repo x86_64 ...
- PHP程序漏洞产生的原因和防范方法
滥用include 1.漏洞原因: Include是编写PHP网站中最常用的函数,并且支持相对路径.有很多PHP脚本直接把某输入变量作为Include的参数,造成任意引用脚本.绝对路径泄露等漏洞.看以 ...