url未加载到UIWebView中

| 我有一个标签栏控件。第一个选项卡包含一个导航控件。在第二个标签上,我要加载网页(例如google.com)。我写的代码为 NPIViewController.h
@interface NPIViewController : UIViewController {
   IBOutlet UIWebView *webView;
}
@property (nonatomic,retain) IBOutlet UIWebView *webView;
@end
NPIViewController.m
- (void)viewDidLoad {
  [super viewDidLoad];
  NSURL *url = [NSURL URLWithString:@\"http://www.google.com\"]; 
  NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
  [webView setScalesPageToFit:YES];         
  [self.webView loadRequest:request];               
}
该页面只是不加载。没有编译或运行时错误。这有什么问题?     
已邀请:
要知道出了什么问题,您可以执行此操作。
- (void)viewDidLoad {
  [super viewDidLoad];
  webView.delegate = self;
  NSURL *url = [NSURL URLWithString:@\"http://www.google.com\"]; 
  NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
  [webView setScalesPageToFit:YES];         
  [self.webView loadRequest:request];               
}
在您的班级中添加此新方法
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
   NSLog(@\"Error : %@\",error);
}
我希望您已经将WebView对象与其在Interface Builder中的出口连接了起来? 谢谢,     
您必须使用https而不是http。如果您使用http,则会收到此错误消息(使用Ravin的代码查看错误): \“由于“应用程序传输安全性”策略要求使用安全连接,因此无法加载资源。”     
创建您的webView
IBOutlet UIWebView *webView;
试试这个代码
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];
    
重新启动您的IOS模拟器。 这确实不明显,但是首先要在IOS模拟器上的Safari中检查某些站点。 重新启动IOS模拟器后,我的webView在模拟器和设备上均成功打开。 看到这个著名的链接。     

要回复问题请先登录注册