2012-12-10 72 views
-1

我嘗試了UIActivityIndi​​cator的概念。在第一個視圖中,我有一個tableView加載了數據和相應的accessorybuttonton。所以當一個tableViewCell的accessorybutton被點擊時,然後DetailsView被加載。同時我添加一個activityIndi​​cator,當accessorybutton被點擊時。xcode中的UIActivityIndi​​cator?

- (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我怎麼停止動畫activityIndi​​cator當presentView被解僱,只顯示的數據activityindicator prevoius視圖。

+0

在您第一次的viewController的viewWillAppear中只需添加如果(![activityIndi​​cator isAnimating]) [activityIndi​​cator stopAnimating]; – Divya

+0

嗨@arizah在DetailsView類中添加activityIndecator而不是firstview,並將其設置爲子視圖,並且當您從url下載數據或者當您想要返回時,只需stopAnimation並移除或隱藏activityindecator ..其非常簡單並且易於使用的傢伙... –

回答

0

DetailsViewviewDidLoad方法只需添加activityIndi​​cator作爲一個子視圖和動畫開始像波紋管..

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

    [activityIndicator startAnimating]; 
} 

而且還stopAnimating當你的數據下載完成或失敗,也波紋管法加入btnBack方法或viewWillDisappear只是添加此波紋管代碼

[activityIndicator stopAnimating]; 
[activityIndicator removeFromSuperview];///Add this line if you want to remove from superview 
+0

我應該在哪裏添加它? – Honey

+0

只是在btnBack方法夥計..也從超級看法刪除看到我更新代碼後1分鐘 –

+0

@ParasJoshi:沒有傢伙,將無法正常工作。他需要關閉第一個視圖的活動指標 –

-1

viewWillAppear的第一視圖下面的代碼添加[activityIndicator stopAnimating];

-(void)viewWillAppear:(BOOL)animated 
{ 
    if (activityIndicator) 
    { 
    [activityIndicator stopAnimating]; 
    } 
} 
+0

仍然有問題? –

+0

它不工作Mithun..What埃爾茲我需要修改? – Honey

+0

@arizah:你需要把它寫在桌子上看看 –

0
在第一種觀點寫的viewWillAppear中方法

[activityIndicator hidesWhenStopped]; 

告訴我,無論是工作或沒有!

快樂編碼!!!!

+0

對不起,但它不工作 – Honey

0

使用下面的代碼

- (void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath 

    { 

     detailView.Id=[empid text]; 

    [activityIndicator stopAnimating]; 

    [self presentModalViewController: detailView animated:NO]; 

     } 

或在您的firstView的viewWillDisappear

{ 

[activityIndicator stopAnimating]; 

[activityIndicator removeFromSuperView]; 

}

相關問題