IOS开发技术问题总结(三)
2016-03-20 22:24
411 查看
三、多线程
1、新建多线程并运行
targetObj欲调用的函数所在的对象的引用
targetObj’sFunctionName
欲调用的目标的函数的名字,要带参数
functionParma
要传入的参数
NSThread *tThread =
[[NSThread alloc]
initWithTarget:targetObj
selector:@selector(targetObj’sFunctionName)
object:functionParma];
[tThread start];
四、通知与消息
1、发送通知
Dim:(id)obj要传给通知接受者的参数
(NSDictionary)dit
如果要传的参数过多可以用字典类传
NSNotificationCenter *nc
=
[NSNotificationCenter defaultCenter];
//不用字典类的传法
[nc postNotificationName:@"通知的标题"
object:obj];
//用字典类的传法
[nc postNotificationName:@"通知的标题"
object:obj
userInfo:dit];
2、订阅消息并执行指定函数
//订阅了消息的对象在释放前应先退订消息!!!NSNotificationCenter *nc =
[NSNotificationCenter defaultCenter];
[nc addObserver:要订阅消息的对象
selector:@selector(订阅了消息的对象在收到消息后要执行的函数的名字:)
name:@"通知的标题"
object:消息的发送者,为nil则接受任意对象发送的消息];
//接受消息后要执行的函数的结构
-(void)要执行的函数的名字:(NSNotification*)temp{
temp.name;//通知的名字
temp.object;//消息附带的参数
temp.userInfo;//如果用字典类传参数则可接受传来的字典类
}
3、退订消息
NSNotificationCenter *nc =[NSNotificationCenter defaultCenter];
[nc removeObserver:要退订消息的对象];
相关文章推荐
- IOS开发技术问题总结(二)
- IOS开发技术问题总结(一)
- 远程推送(支持iOS 9)
- iOS多线程编程之Grand Central Dispatch(GCD)介绍和使用
- ios cordova如何加载远程界面?
- 深入解析iOS应用开发中对设计模式中的桥接模式的使用
- iOS ARC下的cycle retain
- iOS App开发中使cell高度自适应的黑魔法详解
- Mac&iOS Socket编程
- iOS开发------实现图片下载缓存到本地
- Xcode免证书打包ipa
- iOS-NSLayoutConstraint(代码约束)
- ios后台搭建 和那些坑
- IOS屏幕适配自动布局教程(一)
- iOS的socket开发基础
- 仿豆果美食tableview的展开和收缩效果
- 笔记-iOS 视图控制器转场详解(上)
- iOS开发笔记之三十三——常用的MAC以及Xcode操作快捷键
- 笔记-iOS弹幕(源码)实现原理解析
- iOS 对象的归档