gpt4 book ai didi

ios - iOS 在 Web View 中加载 html 文件时屏幕黑屏

转载 作者:行者123 更新时间:2023-11-29 03:17:27 29 4
gpt4 key购买 nike

我试图在 WebView 中加载一个 html 文件,但屏幕变黑了。 View Controller 的层次结构是:查看

Web View Navigation Item This is the tab and there is navigation controller to present the View Controller.

代码:

- (void)viewDidLoad
{

[super viewDidLoad];
// Do any additional setup after loading the view.
self.webView = [[UIWebView alloc] init];
self.view.backgroundColor = [UIColor colorWithPatternImage:[JLTBackgroundHelper getBackgroundImageForLandingView]];
self.webView.opaque = NO;
self.webView.backgroundColor = [UIColor clearColor];

UIViewController *rootVC = [[UIViewController alloc] init];
rootVC.title = @"Contact JLT Sport";
rootVC.view = self.webView;
self.viewControllers = @[rootVC];

NSString *fileName;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// iPad-specific
fileName = @"contact_ipad";
} else {
// iPhone-specific
fileName = @"contact";
}

NSString *htmlFile = [[NSBundle mainBundle] pathForResource:fileName ofType:@"html" inDirectory:@"Assets/web"];

NSURL *url = [NSURL fileURLWithPath:htmlFile];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
_webView.delegate= self;

}


- (BOOL) webView:(UIWebView*)wv shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navType
{
if (navType == UIWebViewNavigationTypeLinkClicked
&& [request.URL.scheme hasPrefix:@"http"])
{
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
return YES;
}

不知道出了什么问题。尝试了 5 个多小时但没有成功。

最佳答案

代替

self.viewControllers = @[rootVC];

试试这个

[self presentViewController:rootVC animated:NO completion:nil];

如果在 viewDidLoad 中呈现 Controller 出现问题,则在 viewDidAppear 中呈现 Controller 。首先,我不清楚为什么要在 Controller 的 viewDidLoad 中创建另一个 View Controller 并向其添加 subview 。

关于ios - iOS 在 Web View 中加载 html 文件时屏幕黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21524198/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com