【问题标题】:page not loading in uiwebview storyboard页面未在 uiwebview 故事板中加载
【发布时间】:2013-06-13 11:44:13
【问题描述】:

我正在尝试从另一个UIViewController 调用一个方法,该方法接受一个字符串(url)作为参数并在UIWebView 中打开它。下面是UIViewController类中IBAction的代码:

-(IBAction)dashboardButtonTapped:(id)sender {

    [self performSegueWithIdentifier:@"dashboard" sender:self];
    Dashboard *db = [[self storyboard] instantiateViewControllerWithIdentifier:@"dashboard"];
    [db openDashboard:@"http://www.google.com"];
}

接受 url 字符串的方法在另一个名为 DashBoard 的类中:

-(void)openDashboard:(NSString *) url {
    [self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}

我没有收到任何错误,但UIWebView 始终为空白。

可能是什么问题?

【问题讨论】:

  • 您是否设置了UIWebView 委托? openDashboard: 真的被调用了吗?
  • 我还没有为 UIWebview 设置代理。是的,它确实被调用了。

标签: objective-c uiwebview nsurlrequest


【解决方案1】:

检查

  1. self.myWebView 插座已连接
  2. self.myWebView 在加载后在任何地方重新初始化

编辑。

好的,原因可能是您正在设置 url 并在 webview 中加载,但它尚未初始化,因为视图 ​​尚未从 nib 加载。传递 url 字符串并存储在实例变量并在 viewDidLoad 方法中将 loadRequest 设置为实例变量中的值

定义一个实例变量

NSString *_urlToLoad;

.m

-(void)openDashboard:(NSString *) url {
    _urlToLoad =[url copy];
}

-(void)viewDidAppear:(BOOL)animated
{
    [self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_urlToLoad]]];
}

【讨论】:

  • @HassanZaheer : 更新答案,试试看
  • 如果下一个视图是 uinavigationcontroller,我如何传递 url 字符串?
  • 我已经做到了。但我收到错误无法识别的选择器发送到实例
猜你喜欢
  • 2012-01-30
  • 1970-01-01
  • 2012-05-24
  • 1970-01-01
  • 2011-06-01
  • 1970-01-01
  • 2014-11-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多