0

我的代码是这样的:

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

  // some process

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

问题是textView没有隐藏。并且progressIndicator工作正常,可能是因为它在其他线程中运行。但是当我试图隐藏textView在其他线程中或在后台执行时,它不起作用。

4

2 回答 2

0

NSTextView是嵌入NSScrollView你也需要隐藏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];
}
于 2013-01-23T13:41:42.123 回答
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];

}
于 2013-01-25T10:43:35.937 回答