I have a locally stored .htm file and I want to pull the raw html string and display it a textview. I know how to display strings in textviews and everything else, I just need to know how to get the inner strong from the locally stored .htm file. Right now all I can pull is the path.
Asked
Active
Viewed 1,495 times
0
-
`stringWithContentsOfURL:` (NSString method) – borrrden Jul 22 '13 at 04:58
1 Answers
2
First, you'll have to add the file to your project and include it in the application bundle:
- add the file to your project
- select the target
- go to the Build Phases tab
- expand the Copy Bundle Resources section
- add the file to the list
This makes sure the file is available when your application runs on the device.
To read the content of the file when your application runs, get the file path:
NSString *path = [[NSBundle mainBundle] pathForResource:@"your_file" ofType:@"htm"];
and then load the file
NSError *error;
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
Things to watch out for:
- check for the error value after reading
- if the file is large, you might want to read it asynchronously

ctrucza
- 172
- 8
-
Awesome thanks! Also, by chance would you know how to make a textview area skip a line so i can display multiple lines of data? – user2578110 Jul 22 '13 at 05:05
-
Maybe this will help: http://stackoverflow.com/questions/3697253/adding-a-line-break-to-a-uitextview – ctrucza Jul 22 '13 at 05:08