我试图在单个 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 内容,但所有接下来的都收到错误消息
- “重新定义‘路径’”
- “重新定义‘url’”
- “重新定义‘请求’”
我还可以清楚地看到我定义了 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/