1

SVProgressHUD プログレス アクティビティ インジケーターを実装しようとしています。[デモ]からクラスをコピーしました。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 メソッドで、[SVProgressHUD Dismiss] を使用して Hud を隠しているそのメソッドで loadInBackground メソッドを呼び出しています。

ブレークポイントを使用してトレースし、把握することをお勧めします。

于 2012-03-21T19:55:10.007 に答える
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 に答える