2016-04-22 47 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]; 
    }