Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在UIWebView中加载本地HTML文件?_Iphone_Ios_Objective C_Uiwebview - Fatal编程技术网

Iphone 如何在UIWebView中加载本地HTML文件?

Iphone 如何在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)];

我是Objective-C的新手。我想知道如何将本地html文件(比如index.html)加载到UIWebView中,我可以像这样加载url

  -(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>
希望它能工作…快乐编码:-)