在我的应用程序中,我的一个视图的加载时间比正常情况要长(它是一个包含许多图片的滚动视图),所以我想我会让用户知道在加载视图时发生了什么。所以我放了一个进度条,它使用计时器来显示通常需要多长时间加载。唯一的问题是,当按钮被触摸时,iPhone 仍会加载视图,然后当新视图打开时,会出现进度条并启动计时器。如何设置它,以便进度条将显示在与按钮相同的视图上,并且当按下按钮时加载第二个视图,当进度条填满时,它会转到第二个视图。这是我到目前为止的代码。
- (无效)按钮
{{
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];
} }