2013-08-16 522 views
0

我還是iOS的新手,在我開發的應用程序中,當用戶從外部源導入文件時出現此視圖。我想有隻執行導入的用戶確認,在動作片, 的hiearchy如下之後:iOS:請求用戶通過ActionSheet確認發送調度隊列請求之前

  • 用戶從他的電子郵件的動產在應用程序中打開該文件。

  • 然後,他切換到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:所以我添加和更改的兩種方法(I似乎無法調用應用程序代理的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; 
     } 


    } 

並將調用導入的功能改爲:

-(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; 
} 

回答

0

無論什麼動作確實會觸發-handleImportURL:的呼叫,而應創建一個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]; 
    } 
} 
+0

你好,我做了一個嘗試(請參見上面)添加動作表,但是如果我刪除OpenUrl函數中的[self handleImportURL:url]它不起作用。 –

0

您應該在您的方法中創建並顯示UIActionsheet,但不會執行任何當前的代碼。當前代碼中的所有代碼都應該移到另一個方法中,並且應該調用該方法,如果用戶點擊了正確的按鈕,請使用代理方法actionSheet:willDismissWithButtonIndex:

+0

你好,我想補充一點,處理按鈕點擊動作片的功能,但它似乎並沒有執行並顯示progressView,即使我不點擊取消 –

+0

您是否將控制器設置爲操作表委託? – Wain

+0

是的,像這樣@interface PVProgressViewController()

相關問題