Sander Schaeffer
Sander Schaeffer

Reputation: 2827

How do I display multiple UIWebViews on a single UIViewController with local files?

I'm trying to show multiple UIWebView's on a single UIViewController, each should show a single HTML file.

In my camView.h file, I've got the following code:

@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;

and in my camView.m file:

@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];

}

Now the issue is that the first UIWebview is displaying the HTML content, but all the next ones are getting the error message

  1. "redefinition of 'path'"
  2. "redefinition of 'url'"
  3. "redefinition of 'request'"

I can also clearly see that I'm defining the same thing 4 times, but removing those definitions will completely wreck the code. My experience with xcode is very low, so I don't actually know how to solve it. Please write in depth what the correct solution to showing multiple UIWebview's is.

Upvotes: 0

Views: 173

Answers (1)

Sishu
Sishu

Reputation: 1558

@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];

    }

Upvotes: 1

Related Questions