views:

47

answers:

1

Hi guys,

I have a UIWebView on my interface and I have added a UIToolbar with a next button and previous button. When I press the next button, I want the WebView to load a different HTML page. BUT I also want to run an if statement to determine which HTML page the WebView currently has in it.

So For example.

If the UIWebView has index.html loaded in it, when the user presses the next button I want it to load about.html.

If the UIWebView has about.html loaded in it, when the user presses the next button I want it to load contact.html. etc.

Here is the way I am setting the WebView:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"PrepareEquipment" ofType:@"html"]isDirectory:NO]]];

Thanks guys!

Stefan.

+2  A: 

How about a simple array or other collection where you store all your pages in the order they should be shown?

NSArray *pagesArray = [NSArray arrayWithObjects:@"index.html", @"about.html", @"contact.html", nil];
NSString *currentPage = [pagesArray objectAtIndex:0];
...

- (NSString *)getNextPage {
  int pageIndex = [pagesArray indexOfObject:currentPage];
++pageIndex;
pageIndex%= [pagesArray count];
NSString *nextPage = (NSString *)[pagesArray objectAtIndex:pageIndex];
currentPage = nextPage;
return nextPage;
}

... and a similar method for going back?

Completely untested...

Joseph Tura
that might be worth a shot! Will try it.
StefanHanotin
Working code, now :)
Joseph Tura
where do I put the First 2 lines?
StefanHanotin
Somewhere in your class before you use the method, e.g. in the init part, or in viewDidLoad if it is a UIViewController...?
Joseph Tura