3

私は SVProgressHUD クラス ( https://github.com/samvermette/SVProgressHUD ) を使用しており、セグエ プッシュを使用して別のビュー コントローラーに接続されているボタンが付いたメイン ビュー コントローラーを取得しました。Main View Controller に次のコードを追加しました。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   [SVProgressHUD showWithStatus:@"Loading"];
   NSLog(@"segue test");
}

私がやりたいことは、他のView Controllerがロードされる前に、HUDを表示する必要があるということです。プログラムを実行すると、最初に NSLog の「セグエ テスト」が出力され、その後、他のビュー コントローラーから NSLog が出力されます。問題は、ボタンが押されたときに HUD が直接表示されないことです。ビュー コントローラがロードされています...

これは私が今持っているものです:

http://i47.tinypic.com/jphh0n.png

http://i50.tinypic.com/vzx16a.png

これは私が必要なものです:

http://i45.tinypic.com/2vcb1aw.png

ブルー スクリーンがロードされたら、「ロード中」の HUD を消す必要があります。

4

1 に答える 1

3

ボタンから直接セグエを接続する代わりに、View Controller クラスからセグエを接続できます。セグエに名前を付けてください。この名前は、後で呼び出すために必要です。

IBAction次に、ロードしているものを最初にロードする最初のボタンにボタンを接続できます。読み込みが完了したら、プログレス HUD を閉じて、セグエを呼び出すことができます。

- (IBAction)loadStuff:(id)sender
{
    [SVProgressHUD showWithStatus:@"Loading"];
    [self retrieveStuff];
}

- (void)retrieveStuff
{
    // I'll assume you are making a NSURLConnection to a web service here, and you are using the "old" methods instead of +[NSURLConnection sendAsynchronousRequest...]
    NSURLConnection *connection = [NSURLConnection connectionWith...];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // Do stuff with what you have retrieved here
    [SVProgressHUD dismiss];
    [self performSegueWithIdentifier:@"PushSegueToBlueScreen"
           sender:nil];
}

最初に何が起こるかをシミュレートしたいだけなら、これを試すことができます:

- (IBAction)loadStuff:(id)sender
{
    [SVProgressHUD showWithStatus:@"Loading"];
    [self retrieveStuff];
}

- (void)retrieveStuff
{
    [NSTimer scheduledTimerWithTimeInterval:2 // seconds
                                     target:self
                                   selector:@selector(hideProgressHUDAndPush)
                                   userInfo:nil
                                    repeats:NO];
}

- (void)hideProgressHUDAndPush
{
    // Do stuff with what you have retrieved here
    [SVProgressHUD dismiss];
    [self performSegueWithIdentifier:@"PushSegueToBlueScreen"
                              sender:nil];
}

編集:単一の画像をダウンロードするために、この GCD ブロックを試すことができます。複数の画像のダウンロードをサポートできるように、これをいじるだけでよいと思います。

- (IBAction)loadStuff:(id)sender
{
    [SVProgressHUD showWithStatus:@"Loading"];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
                   ^{
                        // ... download image here
                        [UIImagePNGRepresentation(image) writeToFile:path
                                                          atomically:YES];

                        dispatch_sync(dispatch_get_main_queue(),
                                      ^{
                                            [SVProgressHUD dismiss];
                                            [self performSegueWithIdentifier:@"PushSegueToBlueScreen"
                                                                      sender:nil];
                                       });
                    });
}
于 2013-03-22T09:26:07.597 に答える