objective c - How do I load a CSV in IOS after saving it locally -


i have csv file i'm downloading s3 account , show in ios app using quicklook framework.

the error i'm getting in console. says

qlpreviewcontroller's datasource shouldn't nil @ point. 

this appears after line of code runs // set data source [previewer setdatasource:self];

here's code downloading file, saving , loading quicklook

-(void)showdocument {     nsstring *stringurl = @"http://jornada.s3.amazonaws.com/dust.csv";     nsurl  *url = [nsurl urlwithstring:stringurl];     nsdata *urldata = [nsdata datawithcontentsofurl:url options:nsdatareadinguncached error:nil];     if ( urldata )     {         nsarray   *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);         nsstring  *documentsdirectory = [paths objectatindex:0];          nsstring  *filepath = [nsstring stringwithformat:@"%@/%@", documentsdirectory,@"tempfile.csv"];          //[urldata writetofile:filepath atomically:yes];          bool newfile = [[nsfilemanager defaultmanager] createfileatpath:filepath contents:urldata attributes:nil];          arrayofdocuments = [[nsarray alloc] initwithobjects:                             filepath, nil];           qlpreviewcontroller *previewer = [[qlpreviewcontroller alloc] init];          [self addsubview:previewer.view];          // set data source         [previewer setdatasource:self];          // item preview         [previewer setcurrentpreviewitemindex:0];     }  }  /*---------------------------------------------------------------------------  *  *--------------------------------------------------------------------------*/ - (nsinteger) numberofpreviewitemsinpreviewcontroller: (qlpreviewcontroller *) controller {     return [arrayofdocuments count]; }  /*---------------------------------------------------------------------------  *  *--------------------------------------------------------------------------*/ - (id <qlpreviewitem>)previewcontroller: (qlpreviewcontroller *)controller previewitematindex:(nsinteger)index {       // break path it's components (filename , extension)     nsarray *filecomponents = [[arrayofdocuments objectatindex: index] componentsseparatedbystring:@"."];      nsarray *filepaths = [[filecomponents objectatindex:0] componentsseparatedbystring:@"/"];      nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     nsstring *documentsdirectory = [paths objectatindex:0];     nsstring *filepath = [documentsdirectory stringbyappendingpathcomponent:[((nsstring *)[filepaths objectatindex:[filepaths count]-1]) stringbyappendingstring:(nsstring*)[filecomponents objectatindex:1]]];      // use filename (index 0) , extension (index 1) path      bool fileexists = [[nsfilemanager defaultmanager] fileexistsatpath:filepath];       if (fileexists) {         //     }     return [nsurl fileurlwithpath:filepath isdirectory:no]; } 

you don't add preview controller's view view - present preview controller. , should after setting data source! so, in order:

qlpreviewcontroller* preview = [qlpreviewcontroller new]; preview.datasource = self; [self presentviewcontroller:preview animated:yes completion:nil]; 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -