//
// ViewController.m
// Test
//
// Created by mk on 13-8-5.
// Copyright (c) 2013年 mk. All rights reserved.
//
#import "ViewController.h"
@interface ViewController (){
BOOL end;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"start new thread …");
[NSThread detachNewThreadSelector:@selector(runOnNewThread) toTarget:self withObject:nil];
// while (!end) {
// NSLog(@"runloop…");
// [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
// NSLog(@"runloop end.");
// }
NSLog(@"ok.");
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)runOnNewThread{
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(startupDone:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:15]];
NSLog(@"run for new thread …");
// sleep(1);
end=YES;
NSLog(@"end.");
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]];
}
-(void)startupDone:(NSTimer *)timer{
static int i = 1;
NSLog(@"makai%i",i++);
}
@end