我正在尝试在单个UIWebView
上展示多个UIViewController
,每个{1}}都应显示一个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内容,但接下来的所有内容都会收到错误消息
我还可以清楚地看到我定义了相同的东西4次,但删除这些定义将完全破坏代码。我对xcode的体验非常低,所以我实际上并不知道如何解决它。请深入了解显示多个UIWebview
的正确解决方案。
答案 0 :(得分:1)
@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];
}