Saving the directory structure when loading local files to UIWebview on iPhone

I notice a little annoyance when working with local files in UIWebview and hope there is an easy way around this problem. In a simplified example, I can say that in my xCode project I have a folder called "WebProject" that contains an html file and a subfolder called "images" where the images are located. The html file refers to images, as you would expect: src = "images / MYIMAGE.jpg", for example, which works just dandy if this is where the regular web page is. However, when loading an html file in UIWebview, this image will not be displayed, because it seems that all the files are simply loaded into one large package folder (so the link to the image is actually: src "MyIMAGE.jpg"). In any case, in order to ensure the directory structure of these files in the main set, so that this does not happen? Thanks!

+6
iphone uiwebview
source share
2 answers

Just create the structure you want in the file system (using finder or something else) and import this tree into your project. Make sure you select "Create folder links for any added folders"

You will notice that these folders are blue instead of the usual yellow used for groups. This folder structure will exist in the bundle, and therefore your relative links will work the way you expect.

Hope this helps.

+3
source share

See this page and this tech note for how to add resources and maintain a directory structure. Make sure you select the radio button that says "Create folder links for any added folders." Then, when you go to write your code, the paths related to the folder will be resolved just as if they were subdirectories. Because they are even in your application resources.

+2
source share

All Articles