1

我正在尝试实现 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

4 回答 4

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(显示进度界面)。

于 2012-09-07T09:47:22.940 回答
0

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

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

我不了解您的要求,但据我所知,您正在显示 [SVProgressHUD show];在您的 startLoading 方法中,然后您在该方法中调用 loadInBackground 方法,在该方法中您使用 [SVProgressHUD dismiss] 隐藏您的 hud;

我会建议你通过使用断点来跟踪它并弄清楚它。

于 2012-03-21T19:55:10.007 回答
0

我有同样的问题。当我将 SVProgressHUD 的一个版本更改为更高版本时,问题就消失了。我当前的版本支持 ARC。

于 2013-06-12T16:48:51.053 回答
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];

}
于 2013-10-22T11:57:17.117 回答