【问题标题】:WebView Does not displayWebView 不显示
【发布时间】:2012-09-19 10:13:58
【问题描述】:

WebView 不显示。 我的代码是

WebViewController.m

#import "WebViewController.h"

@interface WebViewController ()

@end

@implementation WebViewController

@synthesize url, webView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{

    [super viewDidLoad];
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:self.webView];
    [self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


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

@end

在我的

ViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Spit out some pretty JSON for the tweet that was tapped. Neato.
    //NSString *formattedJSON = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:[self.office objectAtIndex:indexPath.row] options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    //NSLog(@"tweet:\n%@", formattedJSON);

    NSObject *vURL = [self.office objectAtIndex:indexPath.row];
    self.URL =vURL;
    WebViewController * vc = [[WebViewController alloc] init];

    vc.url = [NSURL URLWithString:URL];
    NSLog(@"%@",URL);
    [self.navigationController pushViewController:vc animated:YES];

}

【问题讨论】:

  • 当你步入它的时候,vc的价值是什么?
  • 什么值,vc 是我的 webview 控制器的实例
  • URL variable the instance variable backing your URL? What's its value at the time you execute vc.url = [NSURL URLWithString:URL];`? “不会显示”到底是什么意思?控制器根本没有出现,还是网页没有加载?
  • 我只是从 webviewcontroller 的 viewcontroller 发送我的对象。
  • 是的,我明白了。在运行时,什么是有效的 URL?

标签: iphone ios uitableview uiwebview webview


【解决方案1】:

您的代码似乎没问题。我建议实现委托方法

-(void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{}

检查这里是否有任何错误。您还可以使用委托检查加载是否已开始或已完成。

检查你的 self.navigationController 是否为 nil。

Also this link can help you if you are using https.

【讨论】:

    猜你喜欢
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多