我嘗試了UIActivityIndicator的概念。在第一個視圖中,我有一個tableView加載了數據和相應的accessorybuttonton。所以當一個tableViewCell的accessorybutton被點擊時,然後DetailsView被加載。同時我添加一個activityIndicator,當accessorybutton被點擊時。xcode中的UIActivityIndicator?
- (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];
}
直到這工作perfectly..I在DetailsView控件返回按鈕,每當被壓presentmodalViewController被解僱。
-(IBAction)btnBack
{
[self dismissModalViewControllerAnimated:NO];
}
但現在的問題是,我可以看到presentmodalViewController越來越駁回但是開始的時候動畫是accessorybutton挖掘仍然animating.So我怎麼停止動畫activityIndicator當presentView被解僱,只顯示的數據activityindicator prevoius視圖。
在您第一次的viewController的viewWillAppear中只需添加如果(![activityIndicator isAnimating]) [activityIndicator stopAnimating]; – Divya
嗨@arizah在DetailsView類中添加activityIndecator而不是firstview,並將其設置爲子視圖,並且當您從url下載數據或者當您想要返回時,只需stopAnimation並移除或隱藏activityindecator ..其非常簡單並且易於使用的傢伙... –