NSThread 멀티스레드 관련

2789 단어 thread
1.     , 2     ,1>     thread:     ,      nsarray             。2>
[self performSelectorOnMainThread:@selector(update) withObject:nil waitUntilDone:YES];                    ,       btn  title。            waitUntilDone ,   YES         update         NSLog(@"-------------ddddd-----------");       ,     NO  ,      update      。



NSArray * array = [NSArray arrayWithObjects:@"a",@"b",@"c", nil]; therad = [[NSThread alloc]initWithTarget:self selector:@selector(thread:) object:array]; [therad start]; -(void)update { [btn setTitle:@"bbbbb" forState:UIControlStateNormal]; for( int i = 0; i < 100; ++ i ) { NSLog(@"i:%d",i); } } -(void)thread:(NSArray *)array { for( int i = 0; i < 3; ++ i ) { sleep(1); NSLog(@"%@",[array objectAtIndex:i]); } [self performSelectorOnMainThread:@selector(update) withObject:nil waitUntilDone:YES]; NSLog(@"-------------ddddd-----------"); }

좋은 웹페이지 즐겨찾기