iphone - Reading a Text file in xcode -


first off, i'm complete beginner.

this might stupid question, here goes:

i'm working on app contains latin texts users can view , read. i'm using xcode 4 storybord function. theway app built: user selects author - book - app shows text.

i kind of confused because need have various text files, depending on users choice.

as have done or embedded files resource , using below code read-out files

in .h file

-(nsstring *)readfile:(nsstring *)filename; 

in .m file

-(nsstring *)readfile:(nsstring *)filename { nslog(@"readfile"); nsstring *appfile = filename; nsfilemanager *filemanager=[nsfilemanager defaultmanager]; if ([filemanager fileexistsatpath:appfile]) { nserror *error= null; nsstring *resultdata = [nsstring stringwithcontentsoffile: appfile encoding: nsutf8stringencoding error: &error]; if (error == null) return resultdata; } return null; } 

may you

enjoy coding :)

edit

what have done according date change on 1 button click , @ time of viewwillapper call function below

-(void)dateandcontentreload { nslog(@"dateandcontentreload"); nslog(@"appdelegate date: %@",appdelegate.dateselected); self.currentdate = appdelegate.dateselected; nsdateformatter* dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdateformat:@"dd mmmm yyyy"]; nsstring *datestring = [dateformatter stringfromdate: appdelegate.dateselected]; self.navigationitem.title = datestring; [dateformatter setdateformat: @"myyyy"]; nsstring *datecomp = [dateformatter stringfromdate: appdelegate.dateselected]; //nslog(@"date : %@",datestring); nsstring *data; nsstring *path; if(![datecomp isequaltostring: @"12012"]) { nsstring *size = [nsstring stringwithformat: @"%f",appdelegate.size] ; nslog(@"dateandcontentreload size: %f",appdelegate.size); data = @"<html><body><font size='"; data = [data stringbyappendingstring: size]; data = [data stringbyappendingstring: @"'><p>"]; data = @"data not available current date."; data = [data stringbyreplacingoccurrencesofstring: @"\n" withstring:@"<br>"]; data = [data stringbyappendingstring:@"</p></font></body></html>"]; } else { [dateformatter setdateformat:@"mmmmd"]; datestring = [dateformatter stringfromdate: appdelegate.dateselected]; [dateformatter release]; nslog(@"new format: %@",datestring); path = [[nsbundle mainbundle] pathforresource: datestring oftype: @"txt"]; data = nil; nsstring *size = [nsstring stringwithformat: @"%f",appdelegate.size] ; nslog(@"dateandcontentreload size: %f",appdelegate.size); data = @"<html><body><font size='"; data = [data stringbyappendingstring: size]; data = [data stringbyappendingstring: @"'><p>"]; data = [data stringbyappendingstring: [self readfile: path]]; data = [data stringbyreplacingoccurrencesofstring: @"\n" withstring:@"<br>"]; data = [data stringbyappendingstring:@"</p></font></body></html>"]; } [self.currentview loadhtmlstring: data baseurl: nil]; } 

basically read file , display in uiwebview client request it.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -