I have a UIWebView class that is added to each storyboard on load, but when passing into this class the page I require form the parent ViewController it only show the file from the first ever page and on each different page/viewController its the same even though I set it different on each.
Is it somehow caching this page and if so, how can I have a clean UIWebview everytime?
my UIwebview class m file (ContentView.m):
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
NSString *urlpath = [[NSBundle mainBundle] pathForResource:pageToDisplay ofType:@"html" inDirectory:@"pageContent"];
NSURL *url=[[NSURL alloc] initFileURLWithPath:urlpath];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[self loadRequest:request];
}
return self;
}
My Parent view passes the requested page using the following variable pageToDisplay:
Parent View m file:
#import "ContentView.h"
- (void)viewDidLoad {
ContentView *dispalyPageContent = [[ContentView alloc] init];
[dispalyPageContent setPageToDisplay:@"THEpg1"];
[self.view addSubview:dispalyPageContent];
//--
[super viewDidLoad];
}
For each other parent view the code is the same but the [displayPageContent setPageToDisplay:@"THEpg1"]; which should change the page I want, e.g. next view would be [displayPageContent setPageToDisplay:@”THEpg2″];
Is it possible to clear this and load a fresh request each time?
It’s because when you call
ContentView *dispalyPageContent = [[ContentView alloc] init];in yourviewDidLoad, you init it with:And in pathForResource:pageToDisplay at the moment of initializing is some trash.
And then, when you call
[dispalyPageContent setPageToDisplay:@"smth"], it changes nothing, because your classContentViewhas been already inited with some trash inPageToDisplay(Also, you call
[[ContentView alloc] init];and in your code there is onlyinitWithFrame:...for objects ofContentViewclass)You can solve this in this way:
1) in your ContentView.m
2) In your ContentView.h:
3) And then, in viewDidLoad: