IOS-子線程的消息循環

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view, typically from a nib.
    NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(demo) object:nil];
    [thread start];
    
    [self performSelector:@selector(demo1) onThread:thread withObject:nil waitUntilDone:NO];
   
}

- (void) demo {
    
    NSLog(@"I am running");
    //[[NSRunLoop currentRunLoop] run];
    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];
    
    NSLog(@"end");
}

- (void) demo1 {
    
    NSLog(@"I am running on runloop");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end



@end



複製代碼
相關文章
相關標籤/搜索