2011-07-06 5 views
1

lblOverlayView_text.text @ "영어 자막"에서 @ "변경"으로 변경하지 마십시오.내 uilabel 텍스트를 변경할 수없는 이유는 무엇입니까?

변경 방법 및 이유는 무엇입니까?

- (void)video123 { 



    lblOverlayView = [[UILabel alloc] init]; 
    int height=40; 
    lblOverlayView.frame = CGRectMake(0, 480-height, 320, height); 
    lblOverlayView.backgroundColor = [UIColor grayColor]; 
    lblOverlayView.alpha = 0.5f; 
    lblOverlayView.text = @"english subtitle"; 
    lblOverlayView.textColor=[UIColor greenColor]; 
    lblOverlayView.textAlignment=UITextAlignmentCenter; 





    NSString *[email protected]"http://video.ted.com/talk/stream/2011U/Blank/MattCutts_2011U-320k.mp4"; 

    movieURL= [NSURL URLWithString:urlAddress]; 

    //MPMoviePlayerViewController * 
    moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL]; 



    [moviePlayer.view addSubview:lblOverlayView]; 


    [self presentMoviePlayerViewControllerAnimated:moviePlayer]; 


    [NSThread detachNewThreadSelector:@selector(thread) toTarget:self withObject:nil]; 

    NSLog(@"loop test end playback starting..."); 

} 





- (void) thread{ 


    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 


    while (true) 
    { 
     [NSThread sleepForTimeInterval: 0.2]; 

     lblOverlayView.text = @"change"; 

    } 




    [pool drain]; 
} 

답변

7

레이블을 백그라운드 스레드에서 업데이트하고 있습니다. UI 요소는 항상 주 스레드에서 업데이트해야합니다.

[lblOverlayView performSelectorOnMainThread:@selector(setText:) withObject:@"Change" waitUntilDone:NO]; 
+0

감사합니다. 마지막으로 내 uilabel 텍스트가 변경되었으며, UI 요소는 항상 주 스레드에서 업데이트해야합니다 .------ 이상한 이유, 고맙습니다. mortenfast – libai

관련 문제