views:

80

answers:

2

I want to develop a news App such as Engadge etc. The news had loaded from the server, and now I'll save the news included body text and pictures into database(Core Data). Can UIWebView read the datas from Core Data directly, and shows in UIWebview?

Thanks.

A: 

Yes and no. You can store the HTML content in the database (CoreData), to show an article you use: loadHTMLString:baseURL: of UIWebView to show the textual content. The images however is probably best stored outside the database as file because you will have to point the image references in your HTML to an actual file.

You could store the images as BLOBs but then you need to pull those blobs and write as files later for UIWebView to be able to pick them up.

I think the easiest way is to store images as files and but place references to them inside CoreData. That way you can also delete them accordingly later on.

Merrimack
I use ASIHTTPRequest which was supplied by third party to download text and pictures from the serve. Now how to save the data directly as HTML? How to show it with URL?Thanks.
Sean
Files can be stored locally using NSFileManager, look it up in the SDK, specifically createFileAtPath:contents:attributes:. You can view the html file in UIWebView using loadRequest by pointing the NSURLRequest to your filesystem.
Merrimack
A: 

If by directly, you mean without any glue code, then no, not on iOS as of present.

You could however use Core data to store text and image objects as desired. It might not be the best idea to use a UIWebView, but to answer your question, it's definitely possible, and in fact quite easy to do so.

Saurabh G
If I use Core data to store text and image objects, which view class should use?
Sean
From my understanding of your question, you are already parsing the incoming HTML to abstract out the images and the text. You are storing these in a Core Data store. To use a web view to display this information, you would have to regenerate semantic markup. You could use a combination of image views and labels/textviews to achieve your goal.Good reference: http://developer.apple.com/iphone/library/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW1
Saurabh G
If I custom UIView, it means that picture shows in the UIView's number and location must be fixed?
Sean