通过UIbutton objective-c调用位于不同文件夹的html页面 [英] Call html pages located different folder via UIbutton objective-c

查看:122
本文介绍了通过UIbutton objective-c调用位于不同文件夹的html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面有4个按钮,它是 UIViewController ,在我的应用程序中我有4个文件夹,在每个文件夹里面我有一个html文件,我有另一个 webViewController 我应该在 webViewController 中加载这个html文件,我的意思是当点击第一个按钮加载第一个html,如果点击第二个加载第二个HTML和....
你能帮我实现这个:

I have one page with 4 buttons, it's UIViewController, and in my application I have 4 folder that inside of each folder I have one html file , I have another webViewController that I should load this html files inside of that webViewController, I mean when click on first button load first html , if click second load second html and .... would you please help me to implement this:

这是我的方法:

-(void)loadWebView{

NSURL *url = [NSURL fileURLWithPath:[ [ NSBundle mainBundle ] pathForResource:  
@"TestName/TestName1/Test1Name1" ofType:@"html" ]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}

如何将这样的地址放入我的方法

How can I put address like this to my method

@"TestName/TestName1/Test1Name1" 

 I mean @"TestName%d/TestName%d/Test%dName" ofType:@"html" 

并将操作设置为我的按钮,当点击第一个按钮转到第一个按钮时单击第二个按钮时文件夹1和加载html
转到第二个文件夹1并加载html等等...

and set action to my button to when click on first button goes to first Folder 1 and load html when click on second button goes to second Folder 1 and load html and so on ...

这里是我的按钮

- (IBAction)ActionButton1:(id)sender {
NSLog(@"A1");
[self.webViewController loadWebView];
}

- (IBAction)ActionButton2:(id)sender {
NSLog(@"A1");
[self.webViewController loadWebView];
}




. . . .

提前致谢!

编辑:

文件结构文件夹

TestName1

     TestName1

        TestName1.html

第二

TestName2

     TestName2

        TestName2.html


推荐答案

只需在 loadWebView 方法(int)中添加一个参数,然后相应地创建文件路径。 ..

Just add a parameter to your loadWebView method (an int) and create the file path accordingly...

类似

-(void)loadWebView:(int)htmlNum{

    NSString *htmlPath = [NSString stringWithFormat:@"TestName/TestName%d/Test%dName%d",htmlNum,htmlNum,htmlNum];
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:htmlPath ofType:@"html"]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
}

然后为按钮创建一个方法,正确调用它(分配标签)以你的按钮为例可以真正简化你的代码:所有按钮的一种方法......)

You then create a method for your buttons that calls it properly (assigning a tag to your buttons for example could really simplify your code : one method for all buttons...)

- (IBAction)ActionButton:(UIButton*)sender {
    [self.webViewController loadWebView:sender.tag];
}

这篇关于通过UIbutton objective-c调用位于不同文件夹的html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆