views:

730

answers:

2

In my application one of my views takes longer than normal to load (it is a scroll view with many pictures) so I figured I would let the user know what was going on while the view was loading. So I put in a progress bar that uses a timer for how long it usually takes to load. The only problem is that when the button is touched the iPhone still loads the view then when the new view opens the progress bar appears and starts the timer. How can I set it so that the progress bar will appear on the same view as the button and that when the button is pressed the second view loads and when the progress bar has filled up it goes to the second view. Here is the code I have so far.

- (void) button {{
if (!self.baseSheet) {
    baseSheet = [[UIActionSheet alloc] 
                 initWithTitle:@"Please Wait" 
                 delegate:self 
                 cancelButtonTitle:nil 
                 destructiveButtonTitle: nil
                 otherButtonTitles: nil];
    [baseSheet setNumberOfRows:5];
    [baseSheet setMessage:@"Loading Photos"];

    UIProgressView *progbar = [[UIProgressView alloc] initWithFrame:CGRectMake(50.0f, 70.0f, 220.0f, 90.0f)];
    progbar.tag = PROGRESS_BAR;
    [progbar setProgressViewStyle: UIProgressViewStyleDefault];
    [baseSheet addSubview:progbar];
    [progbar release];
}

UIProgressView *progbar = (UIProgressView *)[self.view viewWithTag:PROGRESS_BAR];
[progbar setProgress:(amountDone = 0.0f)];
[NSTimer scheduledTimerWithTimeInterval: 0.5 target: self selector: @selector(incrementBar:) userInfo: nil repeats: YES];
[baseSheet showInView:self.view];

[[self navigationController] pushViewController:[[ScrollViewController alloc] init]
                                       animated:YES];

} }

A: 

Have you tried placing progress bar routine into a completely separate method?

Sometimes I also encounter problems with the execution speed of some routines in a method -- especially with UIView/UIImageView related changes. Sometimes changes from certain view-related routines are actually updated on screen faster than stuff executed BEFORE them actually appear to take place. I find that I can usually correct for this by placing the routines that are displaying view changes too late into a completely separate method, and calling that method BEFORE .

RexOnRoids
A: 

Try with thread