在标签栏应用程序中使用webview

时间:2017-07-09 12:31:10

标签: ios objective-c webview

我正在使用此代码在webview中加载html内容

    - (void)viewDidLoad {
        [super viewDidLoad];

        NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"about.html" ofType:nil]];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [webView loadRequest:request];


    }

选择AboutViewController选项卡(精选)时。程序显示空白屏幕会加载任何类型的HTML内容。 示例程序在以下链接中给出。https://drive.google.com/open?id=0B5pNDpbvZ8SnbEhzMFFTNXJDXzA 为什么代码没有加载html?

1 个答案:

答案 0 :(得分:0)

回顾你的项目,你的代码很好,但真正的问题是你的AboutViewController viewDidLoad没有被调用,你必须将NavigationController的segue类型从push更改为rootViewController,更改为AboutViewController并开始按原样工作

已编辑的代码

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSString *pathString = [[NSBundle mainBundle]pathForResource:@"about.html" ofType:nil];
    if(pathString)
    {
        NSURL *url = [NSURL fileURLWithPath:pathString];
        if(url)
        {
            NSURLRequest *request = [NSURLRequest requestWithURL:url];
            [webView loadRequest:request];
        }
        NSLog(@"%@", url.description);
    }
    NSLog(@"%@", pathString);

}

<强> WAS

enter image description here

应该

enter image description here

<强> RESULT

enter image description here

希望这有助于你

相关问题