0

私はまだiOSに不慣れで、開発中のアプリには、ユーザーが外部ソースからファイルをインポートしたときに表示されるこのビューがあります。ユーザーがアクションシートで階層が次のようになっていることを確認した後にのみ、インポートを実行したいと思います。

  • ユーザーはメールから選択して、アプリでファイルを開きます。

  • 次に、progressView (インポート プロセス中にプログラムによってルート ビューになります) に切り替えます。

  • プロセスが終了し、デフォルトの rootview が元に戻されます。

私が望むのは、progressViewが表示されたらすぐにユーザーが本当にインポートしたいかどうかを尋ねることです.そうでない場合はキャンセルする必要があります(方法がわかりません)

ありがとうございました、

関数は次のとおりです。

- (void)handleImportURL:(NSURL *)url
{



    __block JASidePanelController * controller = (JASidePanelController *)self.window.rootViewController;

    // Show progress window
    UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    __block PVProgressViewController * progressController = [storyboard instantiateViewControllerWithIdentifier:@"kProgressViewController"];


    self.window.rootViewController = progressController;
     // I think here somethings needs to be done with UIActionsheet       
    // Perform import operation
    dispatch_async(dispatch_get_global_queue(0, 0), ^{

        NSError *outError;
        NSString * csvString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&outError];
        NSArray * array = [csvString csvRows];
        [[PVDatabaseController sharedController] importArray:array progressHandler:^(float progress) {
            progressController.progressBar.progress = progress;
        }];

        dispatch_async(dispatch_get_main_queue(), ^{
            self.window.rootViewController = controller;
        });
    });
}

更新:アクションシートで私がやろうとしたことは次のとおりです。

//First the function that calls the handleImport
    -(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    {
        // Handle CSV Import
        if (url != nil && [url isFileURL]) {
            [self handleImportURL:url];
            [self confirmImportAlert];

        }
        return YES;
    }

//アクションシートを表示する

- (void)confirmImportAlert {
    UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"Proceed through Import?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Yes", @"Maybe", nil];
    [myActionSheet showInView: self.window];
}

// what to do 
    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
        if(buttonIndex == 0){
            // Avoid Import
        }
        else{
            [self handleImportURL:_importURL];

            //initiate import
        }
    }

更新 2:そこで、2 つのメソッドを追加して変更しました (アプリ デリゲートで ActionSheetWilldismiss 関数を呼び出せないようです)。

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    NSString *choice = [ actionSheet buttonTitleAtIndex:buttonIndex];
    if(buttonIndex == 0){
        //initiate import
        [self handleImportURL:_importURL];
    }
    else{
        //don't initiate import
    }
}

//This methods creats the action sheet
    - (void)confirmImportAlert {
        // importActionSheet is a property in the appdelegate.h

        if (!self.importActionSheet){
            UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"Proceed through Import?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Yes", nil];
            [myActionSheet showInView: self.window];
            myActionSheet.delegate = self;

            self.importActionSheet = myActionSheet;
        }


    }

import を呼び出す関数を次のように変更しました。

-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    // Handle CSV Import
    if (url != nil && [url isFileURL]) {

        [self confirmImportAlert];
        //[self handleImportURL:url];



    }
    return YES;
}
4

2 に答える 2

0

呼び出しをトリガーしたアクションが何であれ、-handleImportURL:代わりに aを作成しUIActionSheetて表示する必要があります。

たとえばボタンの場合:

-(void)buttonTapped:(UIButton *)sender
{
    // [self handleImportURL:someURL];
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:@"Cancel"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"Confirm",nil];
    [actionSheet showInView:self.view];
}

次に、デリゲート メソッドを実装する必要があります。

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (actionSheet.cancelButtonIndex != buttonIndex) {
        [self handleImportURL:someURL];
    }
}
于 2013-08-16T09:33:24.577 に答える