uialertview - iOS: Asking the user to confirm through ActionSheet before launching a dispatch Queue Request -


i still new ios, , in app developing, there view shows when user imports file external source. have import executed after user confirms in action sheet, hiearchy follows:

  • user choses email open file in app.

  • he then, switched progressview(which programatically becomes root view during importing process).

  • the process finishes , default rootview set back.

what want ask if user wants import progressview shows, , if not has cancel it(i not know how it)

thank you,

here function:

- (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;      // think here somethings needs done 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;         });     }); } 

update: here tried action sheet:

//first function calls 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;     } 

//to show action sheet

- (void)confirmimportalert {     uiactionsheet *myactionsheet = [[uiactionsheet alloc] initwithtitle:@"proceed through import?" delegate:self cancelbuttontitle:@"cancel" destructivebuttontitle:nil otherbuttontitles:@"yes", @"maybe", nil];     [myactionsheet showinview: self.window]; }  //      -(void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindex{         if(buttonindex == 0){             // avoid import         }         else{             [self handleimporturl:_importurl];              //initiate import         }     } 

update 2: added , changed 2 methods(i cant seem call actionsheetwilldismiss function in app delegate):

-(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 action sheet     - (void)confirmimportalert {         // importactionsheet property in 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;         }       } 

and changed function calls import this:

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

whatever action did trigger call -handleimporturl: should instead creat uiactionsheet , show it.

if button example :

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

then need implement delegate method:

-(void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindex {     if (actionsheet.cancelbuttonindex != buttonindex) {         [self handleimporturl:someurl];     } } 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -