0

Update: I have recreated the same steps with a new project targeting iPhone and this time it works; I tried again with iPad only project it doesn't! That's weird isn't it ?

Update2: I found why. I saw blank because I put default webview size control and I can see something only if I rotate the iPad simulator :(

==== In xib file I have drag and drop a UIWebView control in my single view app for IPAD Simulator

I drag and drop from the control to file owner to set the delegate I drag and drop from the file owner to set webView in referencing Outlets

In code I have

// h file

@interface myViewController : UIViewController {

    IBOutlet UIWebView *webView;

}

@property(nonatomic,retain)IBOutlet UIWebView *webView;

@end

// m file

#import "myViewController.h"

@interface myViewController ()

@end

@implementation myViewController

@synthesize webView;

- (void)viewDidLoad
{

    [super viewDidLoad];
    // try following complete url   
NSString *urlString = @"http://www.google.com";

    NSURL *url = [NSURL URLWithString:urlString];

    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

    [webView loadRequest:urlRequest];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

@end
user310291
  • 36,946
  • 82
  • 271
  • 487
  • have you link the webView object declered in your header file with webview in xib – Pavan Kumar Mar 30 '12 at 08:54
  • I guess so as I said " I drag and drop from the file owner to set webView in referencing Outlets" ? – user310291 Mar 30 '12 at 12:15
  • then its perfect your code should work...just try by adding webview delegate in header file,and debug by using webview delegates like - (void)webViewDidStartLoad:(UIWebView *)webView - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error - (void)webViewDidFinishLoad:(UIWebView *)webView – Pavan Kumar Mar 30 '12 at 12:25
  • are you sure that you are having internet connection for device...??jst kidding – Pavan Kumar Mar 30 '12 at 12:33
  • nothing matters even if you add www even simple google.com without www is working in my case with same code – Pavan Kumar Mar 30 '12 at 12:35
  • Update: I have recreated the same steps with a new project targeting iPhone and this time it works; I tried again with iPad only project it doesn't! That's weird isn't it ? – user310291 Mar 30 '12 at 13:08

3 Answers3

2

try that you have connect webview outlet in interfacebuilder and see following code give complete url

  NSString *urlAddress = @”http://www.google.com”;

 //Create a URL object.
  NSURL *url = [NSURL URLWithString:urlAddress];

//URL Requst Object
  NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//Load the request in the UIWebView.
  [webView loadRequest:requestObj];
  • OK thanks it was just mistypo. I have recreated the same steps with a new project targeting iPhone and this time it works; I tried again with iPad only project it doesn't! That's weird isn't it ? – user310291 Mar 30 '12 at 13:08
0

Try & check by encoding the string url :

 urlString=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Kuldeep
  • 2,589
  • 1
  • 18
  • 28
0

may your url is incorrect

try this

  NSString *urlAddress = @"http://www.google.com";
pie
  • 230
  • 1
  • 3
  • 9