2016-04-22 84 views
1

我有標籤欄有5個項目和5個視圖附加到這些項目。當我按下物品並且View正在加載時,我需要顯示活動指示器。我該如何操作?我嘗試着嘗試去做類似於StackOverflow的 問題,但是我無法得到。有人可以解釋和展示如何爲像我這樣的初學者做一個例子嗎?我會非常感謝幫助。按下標籤欄後顯示活動指示器?

回答

0

爲此使用MBProgressHUD。從給定的鏈接從github下載項目只需將mbprogreshud.h和.m文件拖放到您的項目中即可。

那麼當你想展示活動的指標,

進口mbprogresshud.h文件和

[MBProgressHUD showHUDAddedTo:self.view animated:YES]; //to show 

當完成你的任務,並要隱藏,然後活動的指標,

dispatch_async(dispatch_get_main_queue(), ^{ 
    [MBProgressHUD hideHUDForView:self.view animated:YES]; 
}); 

你可以參考該github鏈接的更多細節。它也有關於如何使用它的好信息。

希望這將有助於:)

+0

謝謝!現在它看起來更容易使用。但是我把[MBProgressHUD showHUDAddedTo:self.view animated:YES]設置爲didSelectItem,不知道該放哪裏[MBProgressHUD hideHUDForView:self.view animated:YES];我的問題:如果我把showHUDAddedTo到didSelectItem,指示器出現在加載我的視圖後(我需要它之後,我點擊Tab和之前,當我的視圖顯示錶(視圖= TableView)。也許我做了錯誤的加載我的表視圖:( – Yume

+0

然後在viewdidload中顯示hud,並在您的tableview完全變爲可見時隱藏。 – Lion

0
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { 
    NSLog(@"%@", item); 
} 

使用此代碼在代表和展示活動在每一次點擊。 也可以從URL下面獲得幫助。

iphone : How to display Activity Indicator on clicking Tab Bar?

+1

您的鏈接似乎在錯誤的上下文中。這裏的問題是關於'activityindicator'意思是加載器,當某些任務正在運行時,阻止主線程直到完成。你的鏈接有對'networkactivityindicator'的解釋,當應用程序通過互聯網,wifi等與遠程資源進行通信時,它通常顯示在狀態欄中。 – Lion

0

您好,這裏是我的想法:

1的視圖 - 控制

UIViewController<UITabBarDelegate> 

2-實施UITabbarDelegate添加一些變量的UITabBar控制(當然對於視圖 - 控制,查看你是否需要它):

@property (nonatomic,retain) IBOutlet UITabBar *curTabBar; 
@synthesize curTabBar 

3-在UITabBar代表

-(void)tabBar:(UITabBar)tabBar didSelectItem:(UITabBarItem)item 
    { 
//First of all creat activity Indicator view if not create  
    if(self.activityIndicatorView == nil) 
    {  

     //Create one activity indicator whatever you use, MBProgressHUD ,... 
     UIActivityIndicatorView *oneAcIV = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    } 

    //Add activity indicator 
    [self.view insertSubview:self.activityIndicatorView belowSubview:self.curTabBar];//Or aboveSubview depending on the result you want 


    //Create the new view 

    self.NewView = .... 
    //Add the new View below activty indicator 
    [self.view insertSubview:self.NewView belowSubview:self.activityIndicatorView]; 
    }