我的uilabel文字无法改变,为什么?

lib*_*bai 1 iphone video objective-c

lblOverlayView_text.text不会从@"english subtitle"更改为@"change";

如何改变,为什么不呢?

- (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 *urlAddress=@"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];
}
Run Code Online (Sandbox Code Playgroud)

Mor*_*ast 7

您正在从后台线程更新您的标签.必须始终从主线程更新UI元素.

[lblOverlayView performSelectorOnMainThread:@selector(setText:) withObject:@"Change" waitUntilDone:NO];
Run Code Online (Sandbox Code Playgroud)