PDA

View Full Version : Local Images in UIWebView




chris69d
Mar 1, 2012, 07:32 AM
I am very new to iphone app dev, this is my first app i'm building. I'm trying to get local image to show up with no success. This is the code...


- (void) createContentPages
{

NSMutableArray *pageStrings = [[NSMutableArray alloc] init];
for (int i = 1; i < 5; i++)
{

NSString *contentString = [[NSString alloc]
initWithFormat:@"<html><head></head><body style='padding:0px;margin:0px;'><img src='page%d.jpg' width='320' height='460' /></body></html>", i, i];

[pageStrings addObject:contentString];

}
pageContent = [[NSArray alloc] initWithArray:pageStrings];

}

The code works fine, if i switch the image source to the files hosted remotely it works, but i don't want remote, i want them locally viewed. Any help will be appreciated



OverByThere
Mar 1, 2012, 08:03 AM
Have you included the files (page(number).jpg) in your project?

robbieduncan
Mar 1, 2012, 08:04 AM
You will probably need to set the document base URI to point inside you app (so a file URI).

chris69d
Mar 1, 2012, 08:07 AM
Have you included the files (page(number).jpg) in your project?

included them yes

You will probably need to set the document base URI to point inside you app (so a file URI).
How do i do that? This is my first time coding in Obj C.

Does this bit of code need editing?

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[webView loadHTMLString:dataObject
baseURL:[NSURL URLWithString:@""]];

}

robbieduncan
Mar 1, 2012, 08:18 AM
How do i do that? This is my first time coding in Obj C.

Does this bit of code need editing?

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[webView loadHTMLString:dataObject
baseURL:[NSURL URLWithString:@""]];

}


The basics are nothing to do with Objective-C and everything to do with fairly basic HTML. You need a base (http://htmlhelp.com/reference/html40/head/base.html) tag in the head of the document.

The path to your app can be found with NSBundle (https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html) methods. You can use that to create a file NSURL (https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html) which you can turn into a string.

If you expect code, sorry, I see no value in spoon feeding people answers.

jonnymo5
Mar 1, 2012, 02:43 PM
Why are you using the webview? What are you trying to make?