Results 1 to 6 of 6

Thread: webView

  1. #1


    Member Since
    Nov 04, 2012
    Posts
    3
    webView
    Hello,
    i want to do that when i launch the program its automatically will open google web site in webView (for os x system).
    i dont have prior knowledge of programming language and Xcode.
    thanks !!

  2. #2

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    According to the developer documentation, you want the setMainFrameURL method (see here for more info). I don't have Xcode installed so I can't verify this but you might also be able to set this property when you design the interface.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  3. #3


    Member Since
    Nov 04, 2012
    Posts
    3
    i created a new class with the name "webView" and i put this code:
    [[webView MainFrame] loadRequestNSURLRequest requestWithURL: [NSURL URLWithString:@"http://google.com"]]];
    in AppDelegate.m in applicationDidFinishLaunching function and its says me "use of undeclared identifier 'webView' " but i set the identifier to 'webView'

  4. #4

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    190
    You have to add the WebKit Framework to your project.

    Secondly make sure you have an initialized instance of a WebView class.

    only after that will your code work.

    Also there is another WebView instance method, that only requires a URL String.
    Code:
    - (void)setMainFrameURL:(NSString *)URLString
    Regards Mark

  5. #5


    Member Since
    Nov 04, 2012
    Posts
    3
    ...
    thanks for everyone but it doesn't work..
    here's my project (there isn't errors but it doesn't work):






  6. #6

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    190
    Your code should be more something like this.

    AppDelegate.h
    Code:
    #import <Cocoa/Cocoa.h>
    #import <WebKit/WebKit.h>
    
    @interface AppDelegate : NSObject <NSApplicationDelegate>
    {
        IBOutlet WebView *webView;
        IBOutlet NSTextField *navbar;
        
        NSString *urlText;
    }
    
    @property (nonatomic, readonly, assign) IBOutlet NSWindow *window;
    
    @property (nonatomic, readonly, retain)WebView *webView;
    @property (nonatomic, readonly, retain)NSTextField *navbar;
    
    @property (nonatomic, readwrite, copy)NSString *urlText;
    
    - (IBAction)go:(id)sender;
    
    @end
    AppDelegate.m
    Code:
    #import "AppDelegate.h"
    
    @implementation AppDelegate
    
    @synthesize webView, navbar, urlText;
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        // Insert code here to initialize your application
        
        urlText = [NSString stringWithFormat:@"http://www.Google.com"];
        [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
    }
    
    - (IBAction)go:(id)sender
    {
        urlText = [navbar stringValue];
        [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
    }
    
    @end
    There is a lot of things you have to do, to get this into a fully fledged browser, this is only
    the very basic of code, with no error checking, and it assumes a lot, like the address typed
    into your navbar is a correct address.

    Also you need to implement the frame load delegate protocol, if you want to monitor the
    web page loading progress, or check for network errors.

    Try reading the Apple Developer documentation, relating to the WebKit Framework.

    https://developer.apple.com/library/.../uid/10000164i

    Regards Mark

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 08-22-2011, 09:18 AM
  2. WebView in NSWindow and keyboard events
    By albanvn in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 05-06-2010, 10:17 AM
  3. Bug in WebView cocoa?
    By Toreddo in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 04-28-2010, 04:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •