2012-09-11 3 views
0

내 코코아 앱이 네트워크에서 데이터를 가져 와서 표보기에 콘텐츠를 표시해야합니다. 그래서 데이터가 다운로드 될 때의 회전 스타일을 추가하여 애니메이션을 적용합니다. 그런 다음 NSProgressIndicator의 애니메이션이 NSTableView을 중지하고 다시로드합니다. 이상한 점은 테이블 뷰를 다시로드 한 후에 표시되는 내용이 업데이트되지 않는다는 것입니다. 당신은 테이블 뷰를 스크롤하면 그런 내용이처럼 보여주기 시작합니다 이 enter image description here 다음코코아 : NSProgressIndicator 애니메이션 후 NSTableview 새로 고침

(위의 작은 사각형이 NSProgressIndicator의 프레임 것은) 내 코드입니다 :


- (void)loadOperationData 
{ 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [self _showIndicator]; 
    }); 

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

- (void)_showIndicator 
{ 
    if (indicator == nil) 
    { 
     indicator = [[NSProgressIndicator alloc] init]; 
     [indicator setStyle:NSProgressIndicatorSpinningStyle]; 
     [indicator setUsesThreadedAnimation:NO];// I tried to comment this, but no use 
     int width = 30; 
     CGRect rect = CGRectMake(0, 0, width, width); 
     NSRect selfRect = [_coverView frame]; 
     rect.origin.x = selfRect.size.width/2 - width/2; 
     rect.origin.y = selfRect.size.height/2 - width/2; 
     indicator.frame = rect; 
     [_coverView addSubview:indicator]; 
    } 

    [indicator setHidden:NO]; 
    [indicator startAnimation:self]; 
} 

-(void)getOperationLogProcess{ 

    NSDictionary *tempResutDic = [WebServiceManager getOperationLog];//using synchronous ASIHttpRequest to download data 
    if ([[tempResutDic objectForKey:@"resultCode"] intValue]==100) { 
     self.operationLogArray = [tempResutDic objectForKey:@"items"]; 

     [self performSelectorOnMainThread:@selector(reloadTableview) withObject:nil waitUntilDone:YES];//refresh UI in main thread 
    } 
} 

-(void)reloadTableview 
{ 
    [indicator stopAnimation:self]; 
    [indicator setHidden:YES]; 
    [operationlogTable setEnabled:YES]; 

    if ([_coverView isHidden]) 
    { 
     return; 
    } 

    self.lastUpdateDate = [NSDate date]; 

    [operationlogTable reloadData]; 
} 

-(void)loadOperationData 마우스 클릭 이벤트에 의해 호출됩니다. 그리고 -(void)_showIndicator을 발송 블록에 넣는 이유는 표시기를 표시 할 수 없기 때문입니다. 나는 많은 것을 시도하고 마침내 그것을 선택했다.

표시기에 대한 코드에 주석을 달았 기 때문에 문제가 해결되지 않았기 때문에 문제는 표시기를 표시하는 방식과 밀접한 관련이 있다고 생각합니다.

사용자가 대기 중임을 알리는 표시기가 정말 필요합니다. NSProgressIndicator를 올바르게 사용하는 방법을 알려주세요.

감사합니다.

답변

0

멀티 스레드로 인해 발생했습니다.

- (void)loadOperationData 메인 블록을 사용하여 진행 표시기를 표시하고 백그라운드에서 데이터를 가져 오는 스레드를 만듭니다. 블록은 비동기 적으로 실행되며 때로는 -(void)reloadTableview 다음에 있습니다.

마지막으로, - (void)loadOperationData을 메인 스레드에서 호출하고 - (void)_showIndicator을 블록 밖으로 보냅니다. 그런 다음 고정됩니다.

관련 문제