Friday, 25 September 2015

File Management Basics in IOS


preliminary notes:
using xcode 4.2.1
working ios 5 sdk
have enables arc
using storyboard
had no warning in code
running following in iphone simulator
csv file generated can found within finder, , stores data correctly
these methods implemented in controller of view containing buttons , text inputs (as seen in pic)

[​img]


code:
- (ibaction)storeresults:(id)sender {      nsstring *csvline = [nsstring stringwithformat:@"%@,%@,%@\n",                           self.firstname.text,                           self.lastname.text,                           self.email.text];      nsstring *docdir = [nssearchpathfordirectoriesindomains(                                              nsdocumentdirectory,                                               nsuserdomainmask, yes)                           objectatindex:0];        nsstring *surveyfile = [docdir stringbyappendingpathcomponent:@"surveyresults.csv"];            if (![[nsfilemanager defaultmanager] fileexistsatpath:surveyfile]) {          [[nsfilemanager defaultmanager] createfileatpath:surveyfile contents:nil attributes:nil];      }            nsfilehandle *filehandle = [nsfilehandle filehandleforupdatingatpath:surveyfile];      [filehandle seektoendoffile];      [filehandle writedata:[csvline datausingencoding:nsutf8stringencoding]];      [filehandle closefile];            self.firstname.text = @"";      self.lastname.text =@"";      self.email.text = @"";  }
code:
- (ibaction)showresults:(id)sender {      nsstring *docdir = [nssearchpathfordirectoriesindomains(                                                              nsdocumentdirectory,                                                               nsuserdomainmask, yes)                           objectatindex:0];            nsstring *surveyfile = [docdir stringbyappendingpathcomponent:@"surveyresults.csv"];            if (![[nsfilemanager defaultmanager] fileexistsatpath:surveyfile]) {          nsfilehandle *filehandle = [nsfilehandle filehandleforreadingatpath:surveyfile];          nsstring *surveyresults = [[nsstring alloc] initwithdata:[filehandle availabledata] encoding:nsutf8stringencoding];                    [filehandle closefile];          self.resultsview.text = surveyresults;      }  }
the results won't show in results text field. :mad:

i'm confident of connections set correctly, , have properties set public.
 

i'll remind again:

please don't make me have anymore.

and, yes, can edit title of thread after it's been posted.
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment