2012-02-27 2 views
4

저는 새로운 Mac 프로그래머입니다. NSProgressIndicator을 사용하는 방법에 대한 도움이 필요합니다. 이미 샘플 코드를 찾았지만 아무 것도 찾을 수 없습니다.코코아 진행률 막대를 사용하는 방법?

는 내가하고 싶은 것은 이것이다 :

-(IBAction)startProgressBar:(id)sender; { 

    //I want to make the bar update itself by the value of 1 until it is at the value of 100 
    //Example: add 1 to bar every second until it is full 

} 

답변

8

내가 performSelector:withObject:afterDelay 여기에 당신을 도울 것입니다 생각합니다.

진행률 표시 줄을 증가시킬 방법을 작성하십시오. 그 방법의 끝에서 동일한 방법으로 performSelector:withObject:afterDelay에 1 초의 지연 시간이 걸릴 때까지 전화하십시오.

아마도이 메서드에 개체를 전달할 필요가 없으므로 nil을 사용할 수 있습니다.

편집 귀하의 경우에는

나는 이런 식으로 뭔가 추천 할 것입니다 :

- (IBAction)startProgressBar:(id)sender 
{ 
    // Initialize the progress bar to go from 0 to 100 
    [progress setMinValue:0.0]; 
    [progress setMaxValue:100.0]; 
    [progress setDoubleValue:0.0]; 

    // Start the auto-increment calls 
    [self incrementProgressBar]; 
} 

- (void)incrementProgressBar 
{ 
    // Increment the progress bar value by 1 
    [progress incrementBy:1.0]; 

    // If the progress bar hasn't reached 100 yet, then wait a second and call again 
    if([progress doubleValue] < 100.0) 
     [self performSelector:@selector(incrementProgressBar) withObject:nil afterDelay:1]; 
} 
+0

가 이미 코드 줄을 알고를하지만 난 그게 나에게 자세한 내용을 적어주세요 방법 LOOP 모른다 :) – CocoaCoder

+1

끝에 코드 줄이있는 메서드를 작성한다고 가정 해보십시오. 메서드가 실행 된 후에는 지연 후 다시 실행됩니다. 그리고 다시. 재귀 적 방법과 비슷합니다. – Aaron

+0

네,하지만 바가 100 %가 될 때까지 루프를 만들고 싶습니다. 루프를 멈추고 싶습니다. D – CocoaCoder

관련 문제