将 NSURLRequest/NSURL 传递到另一个 UIViewController 会导致 (null)
我有两个 ViewController,它们都是 UIWebViewDelegates,其中一个我有一个 UIWebview,它基本上列出了一些链接。 第一个 ViewController 定义了这个方法:
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if (inType == UIWebViewNavigationTypeLinkClicked) {
BrowserViewController *browserViewController = [[BrowserViewController alloc] init];
[self.navigationController pushViewController:browserViewController animated:YES];
browserViewController.URL = [inRequest URL];
[browserViewController release];
return NO;
}
return YES;
}
但是当我在第二个控制器中实际 NSLog viewDidLoad 中的 URL 属性时,我总是得到 (null) NSURL。 此外,如果我在上面的尾声中推送第二个控制器后立即执行 NSLog,它实际上会出现在第二个控制器的 viewDidLoad 方法中的 NSLog 之后。
任何人都有任何想法,为什么会发生这种情况?
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) {
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 setURL 消息完成并返回到第一个控制器之前,您不会将其发送到第二个控制器。您需要按照其他顺序执行此操作:
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: