Iphone辅助xib、UIWebview本地htm文件将无法加载。我尝试了很多方法都没有效果
我正在使用自己的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。由于某种原因,我之前能够加载 .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.