NSThread
来源:互联网 发布:怎么下载wps软件 编辑:程序博客网 时间:2024/06/06 08:45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#import "ViewController.h"
@interface
ViewController ()
{
NSThread
*thread1;
NSThread
*thread2;
UIButton *btn;
}
@end
@implementation
ViewController
- (
void
)viewDidLoad {
[
super
viewDidLoad];
btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(30, 30, 50, 50);
[btn setTitle:@
"按钮"
forState:UIControlStateNormal];
btn.backgroundColor=[UIColor greenColor];
[
self
.view addSubview:btn];
//线程创建 主要有两种方法
thread1=[[
NSThread
alloc] initWithTarget:
self
selector:
@selector
(threadfun1) object:
nil
];
[thread1 start];
//此方法创建需要手动启动
//此方法自动启动线程方法
[
NSThread
detachNewThreadSelector:
@selector
(threadfun2) toTarget:
self
withObject:
nil
];
}
-(
void
)threadfun1
{
NSLog
(@
"thread1"
);
//调用主线程更新
[
self
performSelectorOnMainThread:
@selector
(upbutton) withObject:
nil
waitUntilDone:
NO
];
}
-(
void
)upbutton
{
[btn setTitle:@
"123"
forState:UIControlStateNormal];
[
self
performSelector:
@selector
(threadtothread) withObject:
nil
];
}
-(
void
)threadtothread
{
NSLog
(@
"threadtothread"
);
}
-(
void
)threadfun2
{
NSLog
(@
"thread2"
);
}
- (
void
)didReceiveMemoryWarning {
[
super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
0 0
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- NSThread
- G
- wordpress安装
- Executor 概述
- 51nod 1013 3的幂的和(快速幂+逆元)
- JavaScript原生Array常用方法
- NSThread
- DFS(深搜)算法解析
- Codeforces 493D Vasya and Chess 题解
- Dell Dock 无法启动解决办法
- centos6 关于 ssh,svn,tomcat远程不能访问的问题处理过程
- 1037. 在霍格沃茨找零钱
- GCD之信号量机制二
- GCD之信号量机制一
- Ubuntu 14.04下怎么使用chroot创建另外一个系统