- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[self performSelectorInBackground:@selector(multiThread) withObject:nil];
return YES;
}
-(void)multiThread
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
// [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeAction) userInfo:nil repeats:YES];//第一种形式
//
NSTimer *timer= [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timeAction) userInfo:nil repeats:YES];//第二种
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[pool release];
//加NSRunLoop 自动将NSTimer第一种形式 添加到 NSRunLoop
[[NSRunLoop currentRunLoop] run];
NSLog(@"线程结束");
}
-(void)timeAction
{
NSLog(@"timeAction");
}
iOS 多线程 5定时器 NSRunLoop
最新推荐文章于 2024-04-22 12:53:24 发布