首页 > 移动平台 > 详细

IOS--多线程基础

时间:2016-03-02 13:16:23      阅读:151      评论:0      收藏:0      [点我收藏+]

TestController.m

 1 #import "TestController.h"
 2 #import "TestView.h"
 3 
 4 @interface TestController()
 5 
 6 @property(nonatomic,strong)UIButton *button;
 7 
 8 @end
 9 
10 - (void)viewDidLoad
11 {
12     [super viewDidLoad];
13     
14     _button = [UIButton buttonWithType:UIButtonTypeSystem];
15     
16     _button.frame = CGRectMake(0, 20, 100, 20);
17     [_button setTitle:@"Hello" forState:UIControlStateNormal];
18     
19     [_button addTarget:self action:@selector(start:) forControlEvents:UIControlEventTouchUpInside];
20     
21     [self.view addSubview:_button];
22     
23 }
24 
25 
26 -(void)start:(UIButton*)sender
27 {
28     NSThread *t = [[NSThread alloc]initWithTarget:self selector:@selector(thLoop) object:nil];
29     
30     //启动线程
31     [t start];
32 }
33 
34 -(void)thLoop
35 {
36     for (int i =1; i<=10 ; i++) {
37         
38         //睡眠1秒
39         [NSThread sleepForTimeInterval:1];
40         NSLog(@"i=%d",i);
41     }
42     
43     NSLog(@"end");
44 
45 }
46 
47 @end

 

IOS--多线程基础

原文:http://www.cnblogs.com/yuge790615/p/5234307.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!