2013-08-16 1 views
0

저는 아직 iOS에 익숙하지 않습니다. 개발중인 앱에는 사용자가 외부 소스에서 파일을 가져올 때 표시되는보기가 있습니다.iOS : 디스패치 대기열 요청을 시작하기 전에 ActionSheet를 통해 확인하도록 사용자에게 묻습니다.

  • 사용자가 응용 프로그램에서 파일을 열고 자신의 이메일에서 choses : 사용자가 다음과 같이 액션 시트에, 관계의 계층임을 확인 후 나는 단지 실행 가져 오기를하고 싶습니다.

  • 그러면 그는 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; 
     }); 
    }); 
} 

업데이트 : 그래서 여기 나는 액션 시트와 함께 할 뭘하려 :

당신은 여기

는 기능입니다 6,
//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

안녕하세요, 저는 액션 시트에 버튼 클릭을 처리하는 기능을 추가하려고하지만, 취소를 클릭하지 않아도 실행 및 진행보기가 나타납니다. –

+0

컨트롤러를 작업 시트 대리인으로 설정 했습니까? – Wain

+0

예 @interface PVProgressViewController()