views:

682

answers:

1

I want to make a simple app, where a UIWebView with custom content will have several links to other pages with similar content as well (and a navigation bar on top, with just a back button). I read the answers to this question, however I'm not sure if I should do that in my application, as the user might be able to go deep enough, and I will be creating new webviews all the time. What could be the best practice for such a behavior?

Thank you!

+2  A: 

I'd recommend listening for:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

and always returning YES (so the webView will continue with the requested link) while storing each request in an NSMutableArray to create a stack of the user's browsing history.

That would let you update a back button's text with the previous page's title (shortened of course).

If you just need to have a back button without label, you could have a simple button hooked up to the UIWebView's - (void) goBack; method.

Kirk van Gorkom
Thanks for that! With this approach, is it possible to have an animated transition when a new link opens? I guess no, right?
Irene
I tried your code and it works, however I would really like to have this transition animation, this is why I was referring to the UINavigationBar on my original post. Does anybody have an idea about that?
Irene
I assume you're referring to the slide-in-from-the-right animation when pushing a new view controller onto the nav controller's stack. In this case that wouldn't be possible unless you faked it inside the web page using javascript.You could get the animation effect by returning NO to the `shouldStartLoadWithRequest:` message and pushing a new UIWebView, but creating new UIWebViews for each link would get expensive fast.
Kirk van Gorkom
Yes, this is what am I doing now, and even if it works, I know that there has to be a better way. I'm trying to see if I can only use two views and then swap html content in between them, but then I'm confused with what should happen when the "back" button is pressed..
Irene