码迷,mamicode.com
首页 > 移动开发 > 详细

IOS--多线程基础

时间:2016-03-02 13:18:31      阅读:182      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!