Showing posts with label uiwebview. Show all posts
Showing posts with label uiwebview. Show all posts

Thursday, January 26, 2012

problem loading .js (javascript) files in webview

I had a problem where I loaded a local html file but the linked javascript files were not running.  I used iWebinspector to view the problem closer and found that the javascript files were not found.  The solution was to tell Xcode to copy the js file to the Bundle as unchanged resources instead of compiling it.  To do this in Xcode 4:

  1. Select the project in the left pane
  2. Select your target
  3. Select Build Phases
  4. Expand "Copy Bundle Resources"
  5. Add your javascript files to this section.
source:  one of the last responses on http://stackoverflow.com/questions/4591287/problem-loading-js-file-in-webview

Thursday, June 30, 2011

viewWithTag and UIWebview

Be careful when you have a UIWebview as a subview and you are trying to get a view by using viewWithTag.  The UIWebview has subviews of its own and can have the tag you are looking for.  So you may end up with a UIScrollview instead of a UIWebview.  It's best to check what class the view you are getting back is.

Friday, June 17, 2011

Disable UIWebView Scrolling

This will get the UIScrollView in the UIWebView and disable scrolling:

UIView* row = nil;
for(row in webView.subviews){
  if([row isKindOfClass:[UIScrollView class] ]){
    UIScrollView* scrollRow = (UIScrollView*) row;
    scrollRow.scrollEnabled = NO;
    scrollRow.bounces = NO;
  }
}


The  will be rejected as contributors on this blog have experienced:
http://praveenmatanam.wordpress.com/2009/04/03/how-to-disable-uiwebview-from-user-scrolling/

Saturday, June 11, 2011

Show Local Image in UIWebView

In order to load an image from within the app into your UIWebview, the webview needs to have the correct base url.

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];


With the correct base url, the images can be loaded relatively with:



Or in CSS

.someBG {
    background: url(theImage.png);
}

Source: http://stackoverflow.com/questions/747407/using-html-and-local-images-within-uiwebview

Another way to load an image is to convert it to base64 in this post:

http://iphoneincubator.com/blog/windows-views/display-images-in-uiwebview