Load WebView URL inside Notification Bar NSPopover - xcode

I'm a noob OSX Developer having issues getting a WebView to load a URL when inside of a Custom View using NSPopover...My NSPopover is activated when a notification bar item is clicked.
This code is in my application delegate under
"- (void)applicationDidFinishLaunching:(NSNotification *)aNotification":
NSURL*url=[NSURL URLWithString:#"http://www.google.com"];
NSURLRequest*request=[NSURLRequest requestWithURL:url];
[[_webView mainFrame] loadRequest:request];
It works just fine if I move the WebView to any other window, but the WebView in my Custom View for this NSPopover displays as a blank page. Any ideas why? Any additional information you might need? Limitation of the CustomView?

You have created the Outlet in IB for the UIWebView in your Custom View ? and strung it together?

Related

WKWebView in Cocoa app can't get the cursor on click

I created a simple test app where one field is an NSTextField and another is a <textarea> instead a WKWebView. I can click into the web view once, but if I go back to the NSTextField, I'm unable to get the cursor back into the web view ever again.
Here's a demonstration:
As you can see, the web view is still interactive to some extent, it just can't become (I assume) the first responder again.
Is there something weird about WKWebView and the responder chain? How can I make the WebWebView behave like a normal NSTextField?
Here is a sample project built in Xcode 11.5 in case you want to try it out.
How can this be fixed?
The issue seems to be related to the textarea, using content editable <body contenteditable="true"></body> does seem to work.
A workaround for using the textarea is to subclass WKWebView like this:
- (void)mouseDown:(NSEvent *)event
{
[super mouseDown:event];
[[self window] makeFirstResponder:self];
}

performSegueWithIdentifier opens a new window in OS X

I am working on OS X application using Storyboard.
I have 2 view controllers LaunchViewController and MainViewController. WindowController has LaunchViewController as window content. LaunchViewController does some checks and then segues to MainViewController. I would expect to show MainViewController in first Window but instead I see 2 windows one showing LaunchViewController and other using MainViewController.
[self performSegueWithIdentifier:kSegueToContentView sender:self];
Is this expected behaviour? Should I use ContainerView instead of calling performSegue?
I advise using a custom segue in order to avoid opening new view controllers in a new window.
This Code example may help you...

Xcode Webview Output "null"

I'm developing an iPad app that supposed to output a website to another view, but when the second view loads, it comes up null. I'm using storyboard to link a button to push the web view controller and load the webpage into that view. The code works fine in the first view (indicated by NSLog), but NSURL never makes it to the second view (NSLog "Null").
Code in IBAction on first view:
self.sanctuaryWebViewController = [[SanctuaryWebViewController alloc]init];
self.sanctuaryWebViewController.URL = [NSURL URLWithString:#"http://www.website.org"];
Code in ViewDidLoad Second View Controller:
NSURLRequest *requestObject = [NSURLRequest requestWithURL:URL];
[webView loadRequest:requestObject];
I have done this in an Iphone app fine declaring a nav delegate to push the view, but not sure if using storyboard or splitview has anything to do with the problem. I spent hours searching for help and tried several different ways to code, but no go. I think I'm close, but not quite there. Using Xcode 4.4 and running on OS 10.8; IOS 5.1
Thanks for any suggestions
Can you show us more of the second view controller's code? I'm assuming you are using ARC? I assume you mean the result is coming up nil rather than NSNull (there is a difference)? Have you connected the webView in the second view controller to the UIWebView in the Storyboard/IB?
Good luck!
I was declaring UIWebview twice. "webview" and "_webview". I removed the instant variable declared in .h and kept the property. Made sure "_webview" was used. Also, Since I linked a segue to a button, I got rid of the IBAction method and replaced it with the prepareForSegue method, which calls the segue. Really had know idea what I was doing using storyboard. I knew about the segue methods, but did not realize they are not linked to the button like IBAction methods. They seem to be used in similar way as calling xib files, but calling segues.

iPad: Launch MainWindow.xib's primary view without using InterfaceBuilder confi

I get really confused using InterfaceBuilder to setup the main window xib file's primary controller view. Is there a good example or simple way to launch the ViewController I want to show by default in the Application Delegate instead of setting it up in InterfaceBuilder's MainWindow.xib file?
you can show your view by code as
FirstViewController *fvc = [[FirstViewController alloc] init];
[window addSubView:fvc];

WebKit won't render on a layer backed view

I have a simple NSView that hosts a WebView.
When I try to make the view layer backed, the WebView stops rendering content - all it renders are the scroll bars.
For simplicity, I added the following code to the applicationDidFinishLaunching method of the app delegate of a brand new xcode project :-
NSView* view = [window contentView];
[view setWantsLayer:YES]; // This is the problematic line!
WebView* webView = [[WebView alloc] initWithFrame:NSMakeRect(0,0,400,400)];
WebFrame* mainFrame = [webView mainFrame];
[view addSubview:webView];
[mainFrame loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"]]];
If I leave out setWantsLayered the WebKit renders the web page. If I set it, WebKit just renders a white square with scroll bars.
Layer backed WebView's aren't supported. From the Leopard release notes:
Most of the standard views and controls that AppKit and Mac OS X's other Cocoa frameworks provide are able to function in layer-backed mode in Leopard, with the exception of certain specialized views such as WebKit WebViews and Quartz Composer QCViews, whose use in layer-backed mode is not presently supported.
(http://developer.apple.com/mac/library/releasenotes/cocoa/AppKitOlderNotes.html#Animation - Last paragraph of the "New View Animation Facilities, and Layer-Backed View Drawing" section)
You should file a bug with Apple and reference rdar://5270371 as found in this mailing list post http://lists.apple.com/archives/Webkitsdk-dev/2007/Dec/msg00042.html.
This now seems to work.
I have just tried out the same code on Mountain Lion and all is OK.

Resources