Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
I have my app set up with a SegmentedControl to go between different webviews. Here is my code I have
Code:
- (IBAction)changesegment {
	if (segment.selectedSegmentIndex == 0) {
		[blogs loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.316apps.com/blogbinds.html"]]];
	}
	if (segment.selectedSegmentIndex == 1) {
		[blogs loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.316apps.com/scoop.html"]]];
	}
	
}
With it set up like this, you cannot back and forth between the web views without losing your spot on one. Is there anyway I can alter this so that the first time the app is loaded and these are selected it will go to the webviews, but afterwards it will hold your place on each website?
 
Two approaches to consider.

If you're looking mostly to remember the scroll position of each webview, you can do that via a JavaScript call. That's the simple and memory efficient way of remembering state. It's not fast though.

Another way of doing it would be to use two different uiwebviews. Position them directly on top of one another. Use your segmented control to decide which one to hide:

blog1.hidden = YES;
blog2.hidden = NO;

That will keep the exact position and state of the UIWebView, at the expense of keeping both around.
 
Two approaches to consider.

If you're looking mostly to remember the scroll position of each webview, you can do that via a JavaScript call. That's the simple and memory efficient way of remembering state. It's not fast though.

Another way of doing it would be to use two different uiwebviews. Position them directly on top of one another. Use your segmented control to decide which one to hide:

blog1.hidden = YES;
blog2.hidden = NO;

That will keep the exact position and state of the UIWebView, at the expense of keeping both around.
Thanks. The issue I find with this is that I can only set Back, Forward, Stop, and Reload buttons to one of the WebViews.
 
Save the scroll position of the current page before you load the new page. When you come back restore the scroll position. You should only restore the scroll position once the webpage has completed loading (there is a delegate method for that).
 
I don't mean the scroll position I mean the website that view is on. If the user selects a blog article to read, then wants to view the other blog listed I want the webview where they were looking at the first blog to not go back to the original webpage once they click back on the button.
 
The first answer I was given with using 2 webviews and hiding one and displaying the other when segment is selected works well, but the Back Forward Stop and Reload actions can only be used with one of the webviews in the view controller.
 
The first answer I was given with using 2 webviews and hiding one and displaying the other when segment is selected works well, but the Back Forward Stop and Reload actions can only be used with one of the webviews in the view controller.

Why? Just retarget them to the other webview when you switch which ones active.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.