#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// 方式一:
// [NSThread detachNewThreadSelector:@selector(nextThread) toTarget:self withObject:nil];
// 方式二:
// [self performSelectorInBackground:@selector(nextThread) withObject:nil];
// 方式三:
NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(nextThread) object:nil];
[thread start];
}
-(void)nextThread
{
NSLog(@"%@",[NSThread currentThread]);
}
@end

本文介绍了一个iOS应用中处理触控事件并启动新线程的方法。展示了三种不同的线程启动方式,并通过一个简单的例子说明如何在ViewController类中实现这些功能。这有助于开发者更好地理解iOS应用程序中线程管理的具体实现。
548

被折叠的 条评论
为什么被折叠?



