显示Web视图

时间:2013-03-28 05:55:15

标签: iphone uiwebview

我是iPhone开发的新手,我想用UIWebView执行一项简单的任务。我只想在单击根视图控制器中的按钮时在新视图上显示URL。但是,当我这样做时,我得到一个例外

  

NSInvalidArgumentException',原因:'应用程序试图呈现一个   nil模态视图控制器在目标上。

这是我的代码。

WebViewController.m(这是我保留UIWebView

的视图
NSURL *url = [[NSURL alloc] initWithString:@"www.google.com"];
NSURLRequest *requestobj = [NSURLRequest requestWithURL:url];

[webview.delegate self];
[self.view addSubview:webview];
[webview loadRequest:requestobj];

2 个答案:

答案 0 :(得分:0)

<强>问题

错误说你正试图推零值。

要检查的事项

  • 确保WebViewcontroller已正确初始化[不能为零]
  • 确保nib名称为WebViewController
  • 文件所有者具有类名WebViewController

答案 1 :(得分:0)

希望您已通过以下方式定义了webview。 UIWebview是UIView的子类。

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];
相关问题