views:

71

answers:

2

i want to display the web page in my program ,i use the WebView object in my IB (.xib) but it dosent work ,is there any sampel code ,not doc or article?

view_w.h

     @interface view_w : NSObject {
    IBOutlet WebView* Web;
       }
   -(IBAction) google:(id) sender;
    @end 

view_w.m

  -(IBAction) google:(id) sender


  {
    NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
       [Web loadrequest:request];

    }

// error No -loadrequest: method found

+1  A: 

You should connect the webview to an outlet of you view controller class. Then

    NSURL *url = [NSURL URLWithString:@"http://yoursite.com/"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [yourwebviewoutlet loadRequest:request];

That is all.

edit to suppress the warning about the method not found, specify the type correctly:

IBOutlet UIWebView * web; // and use lowercase for variables while you're at it.
mvds
thanks but i did write it, i had error -> NO -Loadrequest: method found!
aden
That's because you made it type `id`, so the compiler doesn't know which methods exist on the object (the compiler doesn't look at the word "Web", it looks at that line that says `id web`). see my updated answer.
mvds
aden
ok. this is programming. in programming you have to be precise. it looks like you didn't use an uppercase V for UIWeb **V** iew.
mvds
aden: Case matters in C and Objective-C. UIWebview is something totally different from UIWebView; most importantly, UIWebView exists whereas UIWebview doesn't (unless you made one, for some reason). Also, are you programming Cocoa, or Cocoa Touch? Cocoa has WebView, whereas Cocoa Touch has (as part of UIKit) UIWebView.
Peter Hosey
my programming is cocoa and UIWebView doesn't exist.i also check IBOutlet WebView* web; i have errors too.
aden
A: 

// view.h

    #import <Cocoa/Cocoa.h>
    #import<WebKit/WebKit.h>

     @interface view : NSObject {
   IBOutlet WebView* webview;
      }
     -(IBAction) google:(id) sender;

     @end

//view.m

   #import "view.h"

    @implementation view
      -(IBAction) google:(id) sender
      {
       [[webview mainFrame] loadRequest:
       [NSURLRequest requestWithURL:
       [NSURL   URLWithString:@"http://www.google.com/finance/converter"]]];
       }

      @end
aden
Just dumping a lot of code doesn't illustrate exactly what the solution was. Again, please be *specific*.
Peter Hosey
you are right:)My Webkit wasn't available:D.
aden
What do you mean by that?
Peter Hosey