我正在尝试 UIActivityIndicator 的概念。在第一个视图中,我有一个 tableView 加载了数据和相应的附件按钮。因此,当点击 tableViewCell 的附件按钮时,将加载 DetailsView。同时,我在点击附件按钮时添加了一个 activityIndicator。
- (void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(143, 220, 37, 37)];
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
activityIndicator.color = [UIColor blackColor];
[self.view addSubview:activityIndicator];
[activityIndicator startAnimating];
activityIndicator.frame=CGRectMake(140, 195, 37, 37);
DetailsView *detailView= [[DetailsView alloc] initWithNibName:@"DetailsView" bundle:nil];
detailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
UILabel *empid=(UILabel*)[cell viewWithTag:117];
detailView.Id=[empid text];
[self presentModalViewController: detailView animated:NO];
[detailView release];
}
然后在 DetailsView 基于它从 firstView 收到的 empid 它加载一些数据
- (void)viewDidLoad
{
activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(143, 220, 37, 37)];
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
activityIndicator.color = [UIColor blackColor];
[self.view addSubview:activityIndicator];
activityIndicator.frame=CGRectMake(140, 195, 37, 37);
////loads data from service url and parsing is done
[activityIndicator stopAnimating];
}
直到这里它工作得很好。我在 DetailsView 中有一个后退按钮,每当按下它时,presentmodalViewController 就会被解除。
-(IBAction)btnBack
{
[self dismissModalViewControllerAnimated:NO];
}
但现在的问题是我可以看到presentmodalViewController 被解除,但是当点击附件按钮时开始动画的activityindicator 仍然在动画。那么当presentView 被解除时,我如何停止动画activityIndicator 并只显示prevoius 视图的数据。