Iphone 如何在UIWebView中加载本地HTML文件?
我是Objective-C的新手。我想知道如何将本地html文件(比如index.html)加载到UIWebView中,我可以像这样加载urlIphone 如何在UIWebView中加载本地HTML文件?,iphone,ios,objective-c,uiwebview,Iphone,Ios,Objective C,Uiwebview,我是Objective-C的新手。我想知道如何将本地html文件(比如index.html)加载到UIWebView中,我可以像这样加载url -(void)viewWillAppear:(BOOL)animated { NSLog(@"willAppear"); UIWebView *myWebView=[[UIWebView alloc]initWithFrame:CGRectMake(20, 20, 400, 400)];
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"willAppear");
UIWebView *myWebView=[[UIWebView alloc]initWithFrame:CGRectMake(20, 20, 400, 400)];
NSURL *url = [[NSURL alloc] initWithString:@"http://www.google.co.in/"];
[myWebView loadRequest:[NSURLRequest requestWithURL:url]];
myWebView.scalesPageToFit = YES;
[self.view addSubview:myWebView];
}
我想加载本地html文件而不是加载url。我该怎么做
我还想调用委托方法
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType,未被调用。非常感谢您提供的任何指导。谢谢。首先,请在谷歌搜索之前阅读苹果文档。我建议您阅读基本的objective c编程概念 关于,我想告诉您如何加载本地html
UIWebView *myWebView=[[UIWebView alloc]initWithFrame:CGRectMake(20, 20, 400, 400)];
NSString *indexPath = [NSBundle pathForResource:@"index" ofType:@"html" inDirectory:nil];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:indexPath]]];
[self.view addSubview:myWebView];
要调用任何委托方法,请首先在类中实现UIWebViewDelegate协议。在界面的声明中,如下所示
@interface YourViewController : UIViewController<UIWebViewDelegate>
希望它能工作…快乐编码:-)首先,在谷歌搜索之前,请仔细阅读苹果的文档。我建议你学习基本的objective c编程概念 关于,我想告诉您如何加载本地html
UIWebView *myWebView=[[UIWebView alloc]initWithFrame:CGRectMake(20, 20, 400, 400)];
NSString *indexPath = [NSBundle pathForResource:@"index" ofType:@"html" inDirectory:nil];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:indexPath]]];
[self.view addSubview:myWebView];
要调用任何委托方法,请首先在类中实现UIWebViewDelegate协议。在界面的声明中,如下所示
@interface YourViewController : UIViewController<UIWebViewDelegate>
希望它能工作…快乐编码:-)