2013-01-23 23 views
0

我的代碼是這樣的:隱藏NSTextView而一些進程正在運行

- (void)buttonClick 
{ 
    [self.progressIndicator startAnimation:self]; 
    [self.textView setHidden:YES]; 

    // some process 

    [self.progressIndicator stopAnimation:self]; 
    [self.textView setHidden:NO]; 
} 

問題是textView不隱藏。 progressIndicator正常工作,也許是因爲它在其他線程中運行。但是當我試圖在其他線程中隱藏textView或在後臺執行時,它不起作用。

回答

0

NSTextViewNSScrollView嵌入你還需要隱NSScrollView

- (void)buttonClick 
{ 
    [self.progressIndicator startAnimation:self]; 
    [self.textView setHidden:YES]; 
    [scrollview setHidden:YES]; 

    // some process 

    [self.progressIndicator stopAnimation:self]; 
    [self.textView setHidden:NO]; 
    [scrollview setHidden:NO]; 
} 
+0

邏輯是好的,但不會工作。 –

+0

那麼,我實際上使用'NSTextField',而不是'NSTextView'。但我認爲線程和UI凍結存在一些問題,因爲在其他情況下'setHidden:'可以正常工作。 – user2004023

0

可以延遲,然後選擇調用,這將同步線程(然而,這未必是做的最好的方式,你可以也使用OperationQueue和GCD)。但這符合你的目的:

我已經使用NSTextField和NSTextView,因爲在你的問題和評論中都包含這兩個。

-(void)someProcess:(id)sender{ 
    for (int i=0; i<100000; i++) { 
     for (int j=0; j<9000; j++) { 
      ; 
     } 
    } 
    NSLog(@"someProcess ends"); 
} 

-(void)startProgressIndicator{ 
    [self.progressIndicator startAnimation:self]; 
} 
-(void)stopProgressIndicator{ 
    [self.progressIndicator stopAnimation:self]; 
} 
-(void)hideScroll{ 
    [self.textField setHidden:YES]; 
    [self.scrollView setHidden:YES]; 
} 
-(void)showScroll{ 
    [self.textField setHidden:NO]; 
    [self.scrollView setHidden:NO]; 
} 


- (IBAction)button:(id)sender { 
    //hide scrollview 
    NSLog(@"hide sv"); 
    [self hideScroll]; 

    //start prog indi 
    NSLog(@"run"); 
    [self performSelector:@selector(startProgressIndicator) withObject:self afterDelay:1]; 

    //some process 
    [self someProcess:nil]; 


    //stop prog indi 
    NSLog(@"stop"); 
    [self performSelector:@selector(stopProgressIndicator) withObject:self afterDelay:1]; 


    //show scrollview 
    NSLog(@"show sv\n\n\n\n"); 
    [self performSelector:@selector(showScroll) withObject:self afterDelay:1]; 

}