2013-08-16 523 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()

相关问题