Hi,
I am developing an tab bar based app. One of the tabs is a navigation controller containing a table view. When a cell is selected it loads the detail view which contains a UIWebView. All this works great. Some of the loaded web pages contain links to other sites and I wanted to open these in a modal view like Twitterific or Echofon etc. I set up the necessary modal view which loads a webview of the clicked link's target. This also works. The modal view has a close button which dismisses the modal view. All good so far.
The problem comes if I click another link in the detail view. Instead of loading the modal view again it simply loads the web page into the detail view replacing the original webview content.
This is my webView:shouldStartLoadWithRequest:navigationType method:
Code:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType) navigationType
{
NSURL *requestURL = [ [ request URL ] retain ];
if (![[requestURL host] isEqualToString: @"www.mywebviewcontent.org"] && navigationType == UIWebViewNavigationTypeLinkClicked) {
NSString *url = [requestURL absoluteString];
NSLog(@"url:%@",url);
ModalWebViewController *controller = [[ModalWebViewController alloc] initWithNibName:@"ModalWebView" bundle:nil];
controller.delegate = self;
controller.detailUrl = url;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
[controller release];
[requestURL release];
return NO;
} else {
[ requestURL release ];
return YES;
}
}
The parentViewController (detail view) also has the usual:
Code:
- (void)modalWebViewControllerDidFinish:(ModalWebViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
What I don't understand is why it works perfectly when the first link is clicked but then fails to load the modal view on other links that are clicked.
The only way to fix is to click the back button on the navigation bar to go back to the table view and then come back to the detail view.
Any ideas would be really appreciated.
Cheers,
Dave