2012-07-25 77 views
1

我要開始按鈕的動作示忙,我用IB行動,下面的代碼:如何在iOS上的按鈕操作上顯示繁忙的指示燈?

busyIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
busyIndicator.center = self.view.center; 
[busyIndicator setColor:[UIColor redColor]]; 
[self.btnInjuryPrevention addSubview:busyIndicator]; 
[self.view addSubview:busyIndicator]; // spinner is not visible until started 

[busyIndicator startAnimating]; 
if(![AppStatus isAppOnline]) { 
    noInternetViewController = [[NoInternetViewController alloc] initWithNibName:@"NoInternetViewController" bundle:[NSBundle mainBundle]]; 
    noInternetViewController.view.tag = CHILD_CONTROLLER_TAG; 
    [self.navigationController pushViewController:noInternetViewController animated:YES]; 
    NSLog(@"Yoy are offline..>!!"); 
} 
else 
{ 
    mInjuryPreventionViewController=[[InjuryPreventionViewController alloc] initWithNibName:@"InjuryPreventionViewController" bundle:nil withHeader:@" Injury Prevention" withId:INJURY_PREVENTION_ID]; 
    mInjuryPreventionViewController.view.tag = CHILD_CONTROLLER_TAG; 
    [self.navigationController pushViewController:mInjuryPreventionViewController animated:YES]; 
    //[mInjuryPreventionViewController release]; 
} 
// [self removeLoadingView]; 
[busyIndicator stopAnimating]; 

我上面的代碼中使用,但忙碌的指示燈將無法啓動,所以,你可以告訴我這是可能的嗎?

+0

請顯示整個方法。該方法是否在'[busyIndi​​cator startAnimating]之後立即結束;'? – dasblinkenlight 2012-07-25 10:20:50

+0

嘗試'UIActivityIndi​​catorViewStyleGray',你可能看不到指示器,因爲我相信它已經在iOS 4中失去了陰影。 – 2012-07-25 10:23:15

+0

確保你設置了活動指示器的框架 - 我相信初始化框架等於CGRectZero。 – 2012-07-25 10:30:06

回答

4

如果您在一個塊中啓動和停止動畫,您將看不到任何內容。你可以將startAnimating方法看作是「當控制權返回到操作系統時開始動畫。」

不清楚爲什麼你需要一個微調。創建視圖控制器需要很長時間嗎?不過,如果你移動視圖控制器的東西到一個新的方法,你可以這樣做:

... 
// create busy indicator 
[busyIndicator startAnimating]; 
[self performSelector:@selector(createViewController) withObject:nil afterDelay:0]; 

... 

// at the end of the createViewController method... 
[busyIndicator stopAnimating]; 
1

正如我從你的給定的代碼首先你是在一些UIViewController和你在哪裏添加你的UIActivityIndi​​catorView,並在所有你做兩個條件if-else你在哪裏初始化其他兩個UIViewController,所以在這個視圖(在if-else之後生成) )你UIActivityIndi​​catorView將如何顯示爲您添加它作爲

[self.view addSubview:busyIndicator]; // spinner is not visible until started 

請定義函數if語句執行?

保留編碼

0

當你開始和回採的busuInde​​cator在一個單一的方法,沒有任何長的處理,這樣既功能milisecons內執行所以你無法在用戶界面上看到busyIndecator。 在UI上顯示busyIndecator或任何插座。 我應該有一段時間,這是人類可識別的。 Like:

[busyIndicator startAnimating]; 
//Do EXTREME PROCESSING!!! 
[busyIndicator stopAnimating]; 
相關問題