Iphone辅助xib、UIWebview本地htm文件将无法加载。我尝试了很多方法都没有效果

发布于 2024-09-25 21:12:23 字数 1132 浏览 0 评论 0原文

我正在使用自己的 xib 文件作为辅助视图加载。我可以很好地加载它,但无法获取其中的 webview 来加载任何内容。我有另一个应用程序可以执行此过程,但它位于主视图中。

这是我正在使用的代码。

@synthesize webView;

- (void)viewDidLoad
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"workshop" ofType:@"htm" inDirectory:@"dirA"];
    NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];

    NSString *htmlString = [[NSString alloc] initWithData: 
       [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];

// to make html content transparent to its parent view -
// 1) set the webview's backgroundColor property to [UIColor clearColor]
// 2) use the content in the html: <body style="background-color: transparent">
// 3) opaque property set to NO
//
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
[self.webView loadHTMLString:htmlString baseURL:nil];
[htmlString release];
}

- (void)dealloc
{   
    [webView release];
    [super dealloc];
}





-(IBAction)switchCanary {

 [self dismissModalViewControllerAnimated:YES];
}

-(IBAction)switchBack {

 [self dismissModalViewControllerAnimated:YES];
}
@end

I am loading as secondary view with its own xib file. I can load it fine, but cannot get the webview in it to load any content. I have another app where this proces works, but it is in the main view.

Here is the code I am using.

@synthesize webView;

- (void)viewDidLoad
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"workshop" ofType:@"htm" inDirectory:@"dirA"];
    NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];

    NSString *htmlString = [[NSString alloc] initWithData: 
       [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];

// to make html content transparent to its parent view -
// 1) set the webview's backgroundColor property to [UIColor clearColor]
// 2) use the content in the html: <body style="background-color: transparent">
// 3) opaque property set to NO
//
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
[self.webView loadHTMLString:htmlString baseURL:nil];
[htmlString release];
}

- (void)dealloc
{   
    [webView release];
    [super dealloc];
}





-(IBAction)switchCanary {

 [self dismissModalViewControllerAnimated:YES];
}

-(IBAction)switchBack {

 [self dismissModalViewControllerAnimated:YES];
}
@end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的笑 2024-10-02 21:12:23

我想通了。由于某种原因,我之前能够加载 .htm 文件。我必须将它们全部更改为 .html,现在它可以工作了。也许最近发生了变化。另一个应用程序是几个 SDK 版本之前的。

I figured it out. For some reason I was able to load .htm files before. I had to change them all to .html and now it works. Maybe a recent change. The other app was a couple SDK versions ago.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文