So it looks like it's setting up mypath correctly on all runs, but on
all but the first run, the NSURLRequest's requestWithURL is failing.
Looks to me like the problem is with the WebView -- mainFrame() shouldn't
be returning <null>.
But you're doing more work than you need by essentially loading it each
time anyway. Why not just load it the first time it's called, and from
then on just show it? Something like making helpWindowIndex a property
set to missing value, and then in your handler check its value, and if
it's not missing value, just makeKeyAndOrderFront_.
I'll give it a shot. I kind of had to cobble it together, there's not a
lot of info on opening local files in a webview, the assumption is
(logically) biased towards loading URLS from an address bar
Sigh, it keeps getting weirder. I moved the initial load steps to applicationWillFinishLaunching:
on applicationWillFinishLaunching_(aNotification)
set my mypath to my NSBundle's mainBundle()'s URLForResource_withExtension_("index","html")
set my helpWindowIndex to NSURLRequest's requestWithURL_(mypath)
helpWIndowWebView's mainFrame's loadRequest_(helpWindowIndex)
end applicationWillFinishLaunching_
It works the first time as always, confirmed by lots of logging:
2012-01-19 16:32:17.471 Derby Score[4154:707] mypath is:
2012-01-19 16:32:17.471 Derby Score[4154:707] file://localhost/Users/jwelch/Documents/Personal Stuff/scripts/Xcode 4/Derby Score/build/Debug/Derby Score.app/Contents/Resources/index.html
2012-01-19 16:32:17.471 Derby Score[4154:707] helpWindowIndex is:
2012-01-19 16:32:17.471 Derby Score[4154:707] <NSURLRequest file://localhost/Users/jwelch/Documents/Personal Stuff/scripts/Xcode 4/Derby Score/build/Debug/Derby Score.app/Contents/Resources/index.html>
2012-01-19 16:32:17.471 Derby Score[4154:707] helpWIndowWebView is:
2012-01-19 16:32:17.472 Derby Score[4154:707] <WebView: 0x400d90560>
2012-01-19 16:32:17.472 Derby Score[4154:707] helpWIndowWebView's mainFrame() is:
2012-01-19 16:32:17.472 Derby Score[4154:707] <WebFrame: 0x400d96800>
Then, on the second try I get:
2012-01-19 16:32:26.930 Derby Score[4154:707] mypath is:
2012-01-19 16:32:26.930 Derby Score[4154:707] file://localhost/Users/jwelch/Documents/Personal Stuff/scripts/Xcode 4/Derby Score/build/Debug/Derby Score.app/Contents/Resources/index.html
2012-01-19 16:32:26.930 Derby Score[4154:707] helpWindowIndex is:
2012-01-19 16:32:26.930 Derby Score[4154:707] <NSURLRequest file://localhost/Users/jwelch/Documents/Personal Stuff/scripts/Xcode 4/Derby Score/build/Debug/Derby Score.app/Contents/Resources/index.html>
2012-01-19 16:32:26.931 Derby Score[4154:707] helpWIndowWebView is:
2012-01-19 16:32:26.931 Derby Score[4154:707] <WebView: 0x400d90560>
2012-01-19 16:32:26.931 Derby Score[4154:707] helpWIndowWebView's mainFrame() is:
2012-01-19 16:32:26.931 Derby Score[4154:707] (null)
However, I don't get any error message now, (because it's not trying to run the loadrequest_ function again), the window pops up, but if I scroll it, it blanks the content, and it's effectively a dead window.
So it looks like the problem is that when I close the window, it loses the connection to the content somehow? But I'm not sure how to deal with it, because if I try to redo the load request in the handler, it just blows up.
--
Religion:
A daughter of Hope and Fear, explaining to Ignorance the nature of the Unknowable.
Ambrose Bierce