ios - 如何使用本地文件在单个 UIViewController 上显示多个 UIWebView?

标签 ios uiviewcontroller uiwebview

我试图在单个 UIViewController 上显示多个 UIWebView,每个应该显示一个 HTML 文件。

在我的 camView.h 文件中,我有以下代码:

@interface camView : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *cam01_valk01;
@property (weak, nonatomic) IBOutlet UIWebView *cam02_valk02;
@property (weak, nonatomic) IBOutlet UIWebView *cam03_valk03;
@property (weak, nonatomic) IBOutlet UIWebView *cam04_tunnel;

在我的 camView.m 文件中:

@interface camView ()

@end

@implementation camView

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    NSString *path = [[NSBundle mainBundle] pathForResource:@"cam1_valk01" ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_cam01_valk01 loadRequest:request];

    NSString [[[NSBundle mainBundle] pathForResource:@"cam2_valk02" ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_cam02_valk02 loadRequest:request];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"cam3_valk03" ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_cam03_valk03 loadRequest:request];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"cam4_tunnel" ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_cam04_tunnel loadRequest:request];

}

现在的问题是第一个 UIWebview 正在显示 HTML 内容,但所有接下来的都收到错误消息

  1. “重新定义‘路径’”
  2. “重新定义‘url’”
  3. “重新定义‘请求’”

我还可以清楚地看到我定义了 4 次相同的东西,但是删除这些定义将完全破坏代码。我对 xcode 的经验很低,所以我实际上不知道如何解决它。请详细写下显示多个 UIWebview 的正确解决方案是什么。

最佳答案

@interface camView ()

@end

@implementation camView

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view. 
   NSString *path = [[NSBundle mainBundle] pathForResource:@"cam1_valk01" ofType:@"html"];
        NSURL *url = [NSURL fileURLWithPath:path];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [_cam01_valk01 loadRequest:request];

        NSString * pathSec = [[NSBundle mainBundle] pathForResource:@"cam2_valk02" ofType:@"html"];
        NSURL *urlSecond = [NSURL fileURLWithPath:pathSec];
        NSURLRequest *requestSecond = [NSURLRequest urlSecond];
        [_cam02_valk02 loadRequest:requestSecond];

        NSString *pathThird = [[NSBundle mainBundle] pathForResource:@"cam3_valk03" ofType:@"html"];
        NSURL *urlThird = [NSURL fileURLWithPath:pathThird];
        NSURLRequest *requestThird = [NSURLRequest requestWithURL:urlThird];
        [_cam03_valk03 loadRequest:requestThird];

        NSString *pathFour = [[NSBundle mainBundle] pathForResource:@"cam4_tunnel" ofType:@"html"];
        NSURL *urlFour = [NSURL fileURLWithPath:pathFour];
        NSURLRequest *requestFour = [NSURLRequest requestWithURL:urlFour];
        [_cam04_tunnel loadRequest:requestFour];

    }

关于ios - 如何使用本地文件在单个 UIViewController 上显示多个 UIWebView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25081476/

相关文章:

php - 无法在 iOS 中解析从 PHP 获取的 JSON

ios - 如何将 UITextView 的边框设置为与 UITextField 的边框颜色相同

ios - Cocos2d-iphone - Sphero 集成

javascript - 源代码和 DOM 有什么区别?

ios - Apple 如何访问 sharedMenuController 项目的 UIWebView PDF 字符串?

swift 3 : How can I add the buttons on the UIWeb View

ios - 两个播放器的 iPad 应用程序 - 哪个播放器触摸了屏幕?

ios - 如何找出 iOS8 上当前使用的键盘?

Swift - 添加一个不与当前 Storyboard View 重叠的 UIView

swift - 'ViewController' 不符合协议(protocol) 'UITableViewDataSource' swift