Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 19, 2012, 01:06 PM   #1
gwelmarten
macrumors 6502
 
Join Date: Jan 2011
Location: England!
Loading local HTML file via IBAction in WebView

Hi
I'm trying to make a button load a local HTML file in a webView on my OSX App. My current code is:

Code:
- (IBAction)returnHome {
    [webView setUIDelegate:self]; 
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
    NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    NSURL *baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
    [[webView mainFrame] loadHTMLString:html baseURL:baseUrl];
}
And this does not load the file "index.html". I've being trauling the forums, but can't see anything similar, though I know it must be quite simple. Does anybody have any ideas as to what's wrong with that code?

Sorry if this is in the wrong place - I wasn't sure where to put it.

Thanks in advance,

Sam
gwelmarten is offline   0 Reply With Quote
Old Feb 19, 2012, 01:13 PM   #2
pmau
macrumors regular
 
Join Date: Nov 2010
Quote:
Originally Posted by gwelmarten View Post
Hi
I'm trying to make a button load a local HTML file in a webView on my OSX App. My current code is:

Code:
- (IBAction)returnHome {
    [webView setUIDelegate:self]; 
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
    NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    NSURL *baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
    [[webView mainFrame] loadHTMLString:html baseURL:baseUrl];
}
And this does not load the file "index.html". I've being trauling the forums, but can't see anything similar, though I know it must be quite simple. Does anybody have any ideas as to what's wrong with that code?

Sorry if this is in the wrong place - I wasn't sure where to put it.

Thanks in advance,

Sam
Google
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"] isDirectory:NO]]];
pmau is offline   0 Reply With Quote
Old Feb 19, 2012, 01:17 PM   #3
gwelmarten
Thread Starter
macrumors 6502
 
Join Date: Jan 2011
Location: England!
Oh shoot...

Ah ok - that's for iOS. Does anybody know how I would change that for OSX? The documentation for webView methods on Apple looks pretty similar for both iOS and Mac OSX.

Sam
gwelmarten is offline   0 Reply With Quote
Old Feb 19, 2012, 02:46 PM   #4
chown33
macrumors 601
 
Join Date: Aug 2009
Quote:
Originally Posted by gwelmarten View Post
Ah ok - that's for iOS.
Are you sure?

The iOS class is UIWebView. That's not the same as WebView.


Quote:
Does anybody know how I would change that for OSX?
Read the WebView class reference. More specifically, read the section on the loadRequest: method.

If you can't figure it out from the class reference doc, please explain exactly which part you're having trouble with.
chown33 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Tags
html, local, objective-c, webview

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Local HTML files on an iphone sakraft1 iPhone Tips, Help and Troubleshooting 1 Mar 8, 2010 02:16 PM
load local html into UIWebView knut iPhone/iPad Programming 5 Jul 8, 2009 01:30 PM
Loading local HTML in UIWebView North Bronson iPhone/iPad Programming 1 Mar 17, 2009 04:57 AM
Calling local html file in WebView TurboLag Mac Programming 3 Jul 9, 2008 10:04 PM
How to get mobileSafari to load an HTML file stored locally on the device? yacoub Jailbreaks and iOS Hacks 5 Oct 16, 2007 09:43 PM


All times are GMT -5. The time now is 12:09 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC