SVProgressHUD未显示活动指示器

时间:2012-03-21 18:49:45

标签: iphone ios svprogresshud

我正在尝试实施SVProgressHUD进度活动指标。我从[demo]。1

复制了这个课程

我的应用加载但活动指示器未显示。这是我第一次尝试使用其中之一,所以任何帮助将不胜感激。

以下是代码:

#import "SVProgressHUD.h"

@implementation QuotesAppDelegate

- (void)startLoading 
{
    //call this in your app delegate instead of setting window.rootViewController to your main view controller
    //you can show a UIActivityIndiocatorView here or something if you like
    [SVProgressHUD show];
    [self performSelectorInBackground:@selector(loadInBackground) withObject:nil];
}

- (void)loadInBackground
{ 
    //do your loading here
    //this is in the background, so don't try to access any UI elements
    [self populateFromDatabase];

    [SVProgressHUD dismiss];

    [self performSelectorOnMainThread:@selector(finishedLoading) withObject:nil waitUntilDone:NO];
}

- (void)finishedLoading
{
    //back on the main thread now, it's safe to show your view controller
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
}


- (void)applicationDidFinishLaunching:(UIApplication *)application {

    [self copyDatabaseIfNeeded];

    [self startLoading];
}

4 个答案:

答案 0 :(得分:5)

对于遇到类似问题的其他人来说,这也可能发生,因为你有一个长循环或一段需要很长时间才能执行的代码。如果发生这种情况,您的进度条将不会显示,直到循环之后,这种方式会失败。

要解决此问题,您需要这样:

- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg

基本上你的代码看起来像这样:

- (IBAction)submitPost:(id)sender {
    //now we show the loading bar and submit the comment
    [SVProgressHUD showWithStatus:@"Submitting post" maskType:SVProgressHUDMaskTypeGradient];
    SEL aSelector = @selector(submitDataOfPost);
    [self performSelectorInBackground:aSelector withObject:sender];
}

这基本上会加载进度条,在后台线程中,将调用您要执行的方法。这可以确保在执行代码的同时更新UI(显示进度hud)。

答案 1 :(得分:0)

首先,您没有将SVProgressHUD添加到视图中。

如果你的类继承自UIViewController,那么[self.view addSubview:];或者如果你的类是简单的UIView然后[self addSubView:];

我不明白你的要求,但据我所知,你可以通过你的代码了解[SVProgressHUD show];在你的startLoading方法中然后你在那个方法中使用[SVProgressHUD dismiss]隐藏你的hud来调用loadInBackground方法;

我建议你使用断点跟踪并找出它。

答案 2 :(得分:0)

我遇到了同样的问题。当我将SVProgressHUD的版本更改为后一版本时,问题就消失了。我目前的版本支持ARC。

答案 3 :(得分:0)

=>

(IBAction)fetchData:(id)sender 
    {    

            [SVProgressHUD showWithStatus:@"Loading..." maskType:SVProgressHUDMaskTypeGradient];
            [self performSelectorOnMainThread:@selector(getDataFromSomeWhere) withObject:nil waitUntilDone:NO];
        }

=>

(void)getDataFromSomeWhere
{

      //Do your data populating here. and dismiss the ProgressHud.
     [SVProgressHUD dismiss];

}