I have two ViewControllers which both are UIWebViewDelegates and in one I have a UIWebview that basically lists a number links. The first ViewController has this method defined:
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if (inType == UIWebViewNavigationTypeLinkClicked) {
开发者_如何学C BrowserViewController *browserViewController = [[BrowserViewController alloc] init];
[self.navigationController pushViewController:browserViewController animated:YES];
browserViewController.URL = [inRequest URL];
[browserViewController release];
return NO;
}
return YES;
}
But when I actually NSLog the URL property in viewDidLoad in the second controller, I always get (null) for the NSURL. In addition, if I do an NSLog right after pushing the second controller in the coda above, it actually appears after the NSLog in the viewDidLoad method of the second controller.
Anyone has any ideas, why this is happening?
You're not sending the setURL message to the second controller until after it's already completed and returned to the first one. You need to do that in the other order:
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if (inType == UIWebViewNavigationTypeLinkClicked) {
BrowserViewController *browserViewController = [[BrowserViewController alloc] init];
browserViewController.URL = [inRequest URL];
[self.navigationController pushViewController:browserViewController animated:YES];
[browserViewController release];
return NO;
}
return YES;
}
精彩评论