Using the Progress Bar Loading a New View

In my application, one of my views is taking longer than usual to load (this is a scroll view with many images), so I figured I want the user to know what is happening while the view is loading. So I added a progress bar that uses a timer for how long it takes to load normally. The only issue is that when the button is pressed, the iPhone still loads the view, and then when a new view opens, a progress bar appears and starts a timer. How can I set it so that the progress bar is displayed in the same view as the button, and when the button is clicked, the second view is viewed, and when the progress bar fills, it goes to the second view. Here is the code I have.

- (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];

      

}}

0


a source to share


1 answer


Have you tried putting the execution routine in a separate method?



Sometimes I also run into problems with the speed of execution of some subroutines in a method - especially with UIView / UIImageView changes. Sometimes, changes in some view-related routines actually update on-screen faster than material being executed before they actually appear. I find that I can usually fix this by putting subroutines that take too long to render view changes into a completely separate method and calling that method BEFORE.

0


a source







All Articles