Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 19, 2012, 02: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, 02:13 PM   #2
pmau
macrumors 6502a
 
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, 02: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, 03:46 PM   #4
chown33
macrumors 603
 
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

Similar Threads
thread Thread Starter Forum Replies Last Post
Help! HTML files won't load from local drive? carbonmotion Web Design and Development 15 Aug 24, 2013 01:49 AM
how to get notified when webview finished loading DavidBlack Mac Programming 4 Jun 28, 2013 04:07 PM
Browsers not loading CSS of local Virtual Host gotenks05 Mac Basics and Help 0 Jun 13, 2013 01:14 PM
Need help with HTML coding (Priority Loading) twiggy0 Web Design and Development 9 Jan 9, 2013 01:12 PM
Help! How to convert local HTML files to PDFs? timidhermit Mac Applications and Mac App Store 4 Oct 8, 2012 11:16 AM

Forum Jump

All times are GMT -5. The time now is 04:37 PM.

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

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC