0

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

在我的

视图控制器.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];

}
4

1 回答 1

0

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

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

检查您是否在此处收到任何错误。您还可以使用委托检查加载是否已开始或已完成。

检查您的 self.navigationController 是否为零。

如果您使用 https,此链接也可以为您提供帮助。

于 2012-09-27T15:28:44.533 回答