How to use WebView on xcode 4.5.1
I’m new to programming and I need to embed a website in my application (which is blank; I only want to embed the website right now). I’ve been searching for it since 5:00 PM (It’s now 9:30 PM) and I still didn’t find anything about that.
What code do I need and in what file I need to write it? What do I have to link together?
I use Xcode 4.5.1 and I’m trying to do a Cocoa application for Mac OS X (not for iOS).
I’m sorry if some of my sentences are not clear, but English is not my primary language.
If you need more information in order to help me, just ask.
- Adding NSTouchBar support after main window has been created
- Adding a copy of an NSTabViewItem from an NSTabView into the same NSTabView
- Calculating number of seconds between two points in time, in Cocoa, even when system clock has changed mid-way
- How to add more localizations to my Xcode Project?
- How to SHA hash in cocoa/iOS
- Google App Engine with ClientLogin Interface for Objective-C
2 Solutions Collect From Internet About “How to use WebView on xcode 4.5.1”
In your AppDelegate.h file, add this line below the
#import <Cocoa/Cocoa.h> line:
and add this line below the
@property (assign) IBOutlet NSWindow *window; line:
@property (assign) IBOutlet WebView *webView;
Select your MainMenu.xib file.
Open the window inside it, then drag a WebView from the Object Library browser into the window. Align and size it.
There should be an icon representing your
AppController object to the left of your UI layout. Control-drag from it to your
WebView inside your window. (Do not control-drag from your
File's Owner icon!) Release the mouse button. A contextual menu should appear, containing the word
webView. Select it.
Add the framework
WebKit.framework to your project. Right-click on your Frameworks folder in the resource list on the left side of the Xcode window. Choose “Add files to “<your project name>”… and select the framework using this path:
Select your AppDelegate.m file.
In your -applicationDidFinishLaunching: method, replace the comment with this code:
// I provided Apple's URL, but this is where you provide your own instead. NSURL *url = [NSURL URLWithString:@"http://www.apple.com"]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; [[[self webView] mainFrame] loadRequest:urlRequest];
Build and run. When the window appears, you should see it load the web page you described in the URL.
A few final words:
I see that you’re new here. What I’ve just done, in the context of Stack Overflow, is to give you a gift. You need to try a little harder looking for resources on the Web. I found two myself, but because they’re a bit old (and the development tools look different enough), I embarked upon this answer. I want you to promise that you’ll work harder to find answers for yourself. A great place to begin is by reading Apple’s own very excellent documentation.
Did you find the Apple tutorial on this very subject:
WebView *webview = [[WebView alloc] init]; // or initialise using the modern-equivalent of InterfaceBuilder [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
- Adding drop shadow to table view cell
- UIView background image resize
- How to query CloudKit for recordID IN
- WKWebView ScaleToFit
- Recording voice in background using AVAudioRecorder
- XCode 8.3 Archive error: Linker command failed with exit code 1
- How to get the build UUID in runtime and the image base address
- What should my Objective-C singleton look like?
- Hiding tabBar showing black bar in Ios7
- Switch universal app to iPhone only app
- Zooming in and out in WebView Cocoa
- why storyboard ui elements not showing on UIViewController in xcode 6?
- Xcode storyboard issue with auto layout not allowing me to move an objects origin.y value
- Unable to find reason for Crash on –
- Exception in iPad, UIImagePickerController must be presented via UIPopoverController