2

In my iOS app I have to have some native code and some web code. I am having a little difficulty integrating the navigation of the two.

For iOS I am using an embedded UINavigationController. In the web app I am using a single page application control with the Application Page doing the navigation through the web pages.

Here is the problem. On the first web page I suppress the navigation, as I want to use the iOS navigation there (to go back to from the main menu). A user taps the a list entry and the 2nd web page appears. Here I want to do the opposite - suppress the iOS Navigation but show the web navigation.

So I use the method shouldStartLoadingWithRequest to control whether or not to show the native UINavigation Controller. [method below]

    - (BOOL)webView:(UIWebView *)webView
    shouldStartLoadWithRequest:(NSURLRequest *)request
            navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *url = request.URL;
    NSString *urlString = [url absoluteString];

    if ([urlString
      isEqual:
          @"https://myURL.xsp"] ||
    [urlString isEqual:@"https://myURL.xsp/"]) {
    [self.navigationController setNavigationBarHidden:FALSE animated:YES];
    } else {
    [self.navigationController setNavigationBarHidden:TRUE animated:YES];
    }

    return YES;
    }

My problem is that when a user taps the web navigation to go back to the first view, the event does not fire again (as I am in the uiWebView I assume and so nothing in iOS has changed) and so I lose the native navigation. What I think I need is a way to fire off this method if the uiView changes?

Or is there a better way to handle this?

stwissel
  • 20,110
  • 6
  • 54
  • 101
Bryan Schmiedeler
  • 2,977
  • 6
  • 35
  • 74
  • 1
    Use `-isEqualToString:` for string comparisons. Also, are you sure that the method doesn't get called at all? Seems like you should get a call with `navigationType` (which you're currently ignoring) set to `UIWebViewNavigationTypeBackForward`. – Caleb May 23 '14 at 21:26
  • OK I understand what you are saying. I added the ToString. Thanks for catching that. I have debugged and when I go to the next page the method is fired, but when I go back it is not. I *believe* this is because the back button is in the Xpage, NOT in the iOS code, so probably the iOS does not know anything about going back? How can I fire this event even when the navigation is inside the web page? – Bryan Schmiedeler May 27 '14 at 16:27
  • OK I believe I have it now. No matter what I did this was NOT firing when I did the back button. I had set the resetContent property to "true" but the event STILL wouldn't fire. I reconstructed the page and tried it again and now the even fires, and I am able to run the test again. It works. Thank you very much. How can I give you credit? – Bryan Schmiedeler May 27 '14 at 20:25

0 Answers0