Local Images in UIWebView

Discussion in 'iOS Programming' started by chris69d, Mar 1, 2012.

  1. macrumors newbie

    Joined:
    Mar 1, 2012
    #1
    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...


    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
     
  2. macrumors newbie

    OverByThere

    Joined:
    Nov 24, 2011
    Location:
    Rugby, UK
    #2
    Have you included the files (page(number).jpg) in your project?
     
  3. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    You will probably need to set the document base URI to point inside you app (so a file URI).
     
  4. thread starter macrumors newbie

    Joined:
    Mar 1, 2012
    #4
    included them yes

    How do i do that? This is my first time coding in Obj C.

    Does this bit of code need editing?
    Code:
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        [webView loadHTMLString:dataObject 
                        baseURL:[NSURL URLWithString:@""]];
        
    }
    
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    The basics are nothing to do with Objective-C and everything to do with fairly basic HTML. You need a base tag in the head of the document.

    The path to your app can be found with NSBundle methods. You can use that to create a file NSURL which you can turn into a string.

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

    Joined:
    Jan 21, 2008
    Location:
    Texas
    #6
    Why are you using the webview? What are you trying to make?
     

Share This Page