#import "ViewController.h"
#import "WZJthread.h"
@interface ViewController ()
@property (nonatomic, strong) WZJthread *thread;
@end
@implementationViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.thread = [[WZJthread alloc] initWithTarget:self selector:@selector(run) object:nil];
[self.thread start];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event{
[self performSelector:@selector(text) onThread:self.thread withObject:nil waitUntilDone:NO];
}
//下面这个方法是在这个线程所做的事情
- (void)text{
NSLog(@"%s",__func__);
}
//下面这个方法只为了保住这个线程
- (void)run{
[[NSRunLoop currentRunLoop] addPort:[[NSPort alloc] init] forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
}
@end
网友评论