Testcontroller.m
1 #import "TestController.h"2 #import "TestView.h"3 4 @interfaceTestController ()5 6@property (nonatomic,strong) UIButton *button;7 8 @end9 Ten- (void) Viewdidload One { A [Super Viewdidload]; - -_button =[UIButton Buttonwithtype:uibuttontypesystem]; the -_button.frame = CGRectMake (0, -, -, -); -[_button Settitle:@"Hello"Forstate:uicontrolstatenormal]; - + [_button addtarget:self action: @selector (start:) forcontrolevents:uicontroleventtouchupinside]; - + [Self.view Addsubview:_button]; A at } - - --(void) Start: (uibutton*) Sender - { -Nsthread *t = [[Nsthread alloc]initwithtarget:self selector: @selector (Thloop)Object: nil]; in - //Start Thread to [t start]; + } - the-(void) Thloop * { $ for(inti =1; i<=Ten; i++) {Panax Notoginseng - //Sleep 1 seconds the[Nsthread Sleepfortimeinterval:1]; +NSLog (@"i=%d", i); A } the +NSLog (@"End"); - $ } $ - @end
ios--Multithreading Basics