1

私の問題は、このボタンの下のアクションが完了したときにのみ画面から消えるActionSheetがあることです。私の問題は、アクションシート内の[保存]をクリックしてから、アクションシートを閉じてからアラートを表示し、保存が完了するまで待つようにユーザーに通知したいということです。現在は動作が異なります。最初にアクションシートが表示され、次にアクションシートの下に保存メッセージが表示され、最後にアクションシートが表示から削除されます。そのため、ユーザーにはアラートメッセージは表示されません。

xcodeよりも早くactionSheetを閉じる方法は?

sheetActionButtonの下のメソッド:

- (IBAction)saveAction:(id)sender
{
UIAlertView *alert;
alert = [[[UIAlertView alloc] initWithTitle:@"Saving photo to library\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];

[self saveImageToCameraRoll];

[alert dismissWithClickedButtonIndex:0 animated:YES];
}
4

1 に答える 1

2

メソッドを別のスレッドに移動するsaveImageToCameraRollか、少なくともメインスレッドで非同期に移動する必要があります。次に、アラートを閉じて、saveAction:完了する前に戻ることができます。

これを行う最も簡単な方法は、を使用することdispatch_asyncです。別のスレッドまたはメインスレッドdispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)のキューを取得するために使用します。dispatch_get_main_queue()他のスレッドでUI作業を行わない(またはスレッドセーフではないAPIを使用しない)ようにしてください。


編集:詳細:

- (IBAction)saveAction:(id)sender {
    UIAlertView *alert;
    alert = [[[UIAlertView alloc] initWithTitle:@"Saving photo to library\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
    [alert show];
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
    [indicator startAnimating];
    [alert addSubview:indicator];
    [indicator release];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // Save in the background
        [self saveImageToCameraRoll];
        dispatch_async(dispatch_get_main_queue(), ^{
            // Perform UI functions on the main thread!
            [alert dismissWithClickedButtonIndex:0 animated:YES];
        });
    });
}
于 2011-08-22T06:57:19.633 に答える