Cocoa webView to display a web page - cocoa

I am trying to develop an export aperture plugin, I have designed some views/windows and everything runs smoothly, but trying to now add a webView on one of the window, and cannot make it to display the linked url (hard typed in the code).
Is webView not supported because I'm running it within aperture? anyone having problem with this?
I'm not getting any errors, and used the webView object in the simplest way as possible.
The code to load the web page on webView:
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"]]];

Make sure you hooked up the outlet to the web view in IB (assuming that the web view is in a nib). Many, many Cocoa programmers forget that.
If it's not in a nib, please edit your question to include the code you used to create it.

Related

Showing views in interface builder outside viewcontroller hierarchy in xcode5

I often make use of views in interface builder that live outside of the viewcontroller hierarchy (see screen grab below for simple example).
Before upgrading to Xcode5 I could get this view to appear on the storyboard by writing an IBAction outlet and dragging a connection from the code to the view in the storyboard.
If you paused over the button for a moment it would flash and then open up as a view on the storyboard that is then a lot easier to work with.
Since upgrading this function no longer seems available. Has anyone found out how to get these views to appear on the storyboard?
Edit:
Using the temporary viewcontroller as described in this answer seems one approach, although fiddly since you need to move the UIView stack between viewcontrollers each time you want to edit the layout. Using a separate XIB is starting to seem like the sanest approach.
https://stackoverflow.com/a/13713385/1060154
Finally, we get this back in Xcode 7.
Hallelu!

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.

Weird bugs and undefined behavior of Mac App

At the moment I am experiencing a really weird behavior of my Mac App.
On my Mac (and on all other testing Macs) everything works fine. The app simply works, no leaks,...
BUT on all the review Macs (Yes, on all) it fails: First the launch failed and now, after submitting it more times and trying to workaround the bug, it does not get initialized: Icons that should get loaded dynamically are not shown.
WHY?! Perhaps anyone has made experiences with such a problem because I cannot test it. I try to find the issue but it's nearly impossible.
[EDIT]
App Information:
My app should list all the currently running applications and display them in some way. It reads no files, only the NSUserDefaults to setup itself.
Structure:
appDidFinishedLaunching setups basic stuff like global hotkeys, loads the NSUserDefaults and finally forwards the message to the subclassed main window (<- There is the problem).
There it should load its interface which does not work on review Macs.
I was able to "override" or "fix" this by a little, dirty code snippet but it does not fix the main problem:
//AppDelegate.m
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self performSelector:#selector(didLaunch) withObject:nil afterDelay:0.5f];//<- THIS does the trick, so that the app launches and shows the static content of the NIB, but NO dynamic content is displayed: exactly the same nib state
//Register hotkeys, load NSUserDefaults,
[mainview launched];//<- Here is the problem
finishedLaunching=1;//global var
}
-(void)didLaunch//Launching works
{
if (finishedLaunching==0) {//=0 because of the review results
//Does all the stuff that [mainview launched]; is supposed to do: Display window and setup position
//Calling methods included in main view does not work (OR the window is not refreshed
//so the first start finally works, but the interface is EMPTY, only static content visible
}
}
Does the setup not happen because it is done in its subclassed window?
Why does it work on my Mac (and another Mac mini)?
Do you know why this happens, a way how to correct it or how to reproduce the bugs?
I really need your help and appreciate every tip!

first mac app - push viewcontroller

I have a question, I do some iphone application and now I want to do a little mac application.
From a clean application I add a button on MainMenu xib, than I add a NSViewController to MainMenu (from IB) with one Action.
I create a new NSViewController (FirstViewController) with a nib file and a button.
Now I want only to create a function to push FirstController from MainMenu and a simple function to push MainMenu from FirstController.
something like this
ViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController: ViewController animated:YES];
How can I do it???
I think you're trying to bring an iOS-style interface to MacOS X, and that won't work in many cases. The MacOS X user interface is very different from that of iOS.
iOS apps are limited to a single (and often small) window, and users generally do one thing at a time. The navigation interface standardizes the way that users drill down through different parts of a task so that the journey is predictable. The interface is very modal in the sense that the user is constantly navigating between different parts of the app, and user actions are often linked to the part of the app that's active.
The desktop, on the other hand, has plenty of screen space and allows multiple windows. Desktop apps should be modeless -- a user doesn't navigate through the app, but sees the whole thing laid out before him or her. As much as possible, the user should be able to perform any action at any time.
For these reasons, there is no navigation controller in Cocoa similar to Cocoa Touch's UINavigationController. If you can tell us more about the tasks that your two view controllers manage, perhaps someone here will help you think of ways to translate that better to the expected desktop experience.
Here apple discusses the migrating iOS to OS X strategies. Your scenario is also discussed here:
For example, AppKit uses the NSBrowser class to manage the display of
hierarchical information; in contrast, an iOS app would use navigation
controllers.
And NSBrowser can be seen in use here with the output as shown in the attached image.

How do I use multiple views in my iPad app?

I am trying to build an fairly simple iPad app that requires me to navigate through multiple views. What I want to do is have some sort of main menu view with multiple buttons on it, and when you click one of the buttons the new view appears and then you work with that. I'm new to iPad development, so I have a few questions about the best way to get this done.
1) If I build the views in Interface Builder, how do I make them aware of each other in Xcode? I can't seem to figure out what I need to do in order to code a button to say "Open View 'Foo'"
2) When I open the views, how should I be adding them in relation to the main menu view? Should I add the new view as a subview of the main menu view, or should I close the main menu view, open the new view, and then reopen the main menu upon closing the first view? I imagine both ways are possible, but are there any performance implications I should be aware of?
Thanks,
Mike
I'm making an assumption that it's more or less the same between iPhone and iPad. I haven't started iPad development yet.
You make view controllers aware of each other by importing their headers in your implementation files
FirstViewController.m
#import "SecondViewController.h"
If you're going for a navigation-style app, you should embed your top level view controller in a navigation controller, then you advance to the next one by calling
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
//set any properties
[self.navigationController pushViewController:secondVC animated:YES];
[secondVC release];

Resources