views:

932

answers:

1

Hello,

I have a "didSelectRowAtIndexPath" action that adds a navigation bar and displays a new view. There's an action in the new view that pushes another view onto the navigation stack, and it works, but clicking "back" doesn't restore the previous view.

The sequence is basically:

  • user clicks table cell
  • Navigation bar appears, with new view below it, showing some html with links
  • user clicks a link and new view is added to nav, along with a back button
  • user clicks back button, nav rolls back properly, but view doesn't change

The new view is added by capturing a click on a link like so:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if(navigationType == UIWebViewNavigationTypeLinkClicked) {
 UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"webpage"];
 [flipsideNavigationBar pushNavigationItem:navigationItem animated:YES];
 [navigationItem release];

 WebViewController *viewController = [[WebViewController alloc] initWithNibName:@"webView" bundle:nil];
 UIView *webPageView = self.webViewController.view;
 [webPageView addSubview:viewController.view];
 [webPageView insertSubview:flipsideNavigationBar aboveSubview:viewController.view];
 [[viewController.view.subviews objectAtIndex:1] loadRequest:request];
 [webView stopLoading];
 return YES;
}
return YES;
}

I'm not sure what I'm doing wrong; what should happen is the "back" button should dismiss the current view and return to the previous. Can anyone suggest anything to try?

Thanks!

John

A: 

The recommended way to do this is to just use a UINavigationController and push UIViewControllers onto the stack, either modal or non-modal.

If you wish to stick with your custom solution, you should set a delegate for your UINavigationBar and implement its shouldPopItem: or didPopItem: methods. Documentation link

MrMage
thanks for the good info. It required a bit of a rewrite, but now it works.