1

我遇到了 UIWebView 的问题。如果 iframe 正在加载某些内容并且由于某种原因我更改了源或删除了元素,我会收到以下异常:

MyApp[5812:11303] shouldStartLoadWithRequest
2013-03-14 18:48:45.899 MyApp[5812:11303] shouldStartLoadWithRequest
2013-03-14 18:48:45.900 MyApp[5812:11303] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInvalidArgumentException> *** setObjectForKey: key cannot be nil
2013-03-14 18:48:45.901 MyApp[5812:13603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'
*** First throw call stack:
(0x1c94012 0x10d1e7e 0x1d170de 0x26e35ce 0x26e5693 0x26d44b5 0x2bf8747 0x2bf5610 0x2ec841a 0x2ec6c49 0xb0108ef 0x6619e11 0x6572fc3 0x2dd9d34 0x2eacd15 0x2b31eac 0x2b31c76 0x317bce9 0x2b176d5 0x2b184a5 0x316ade9 0x2b1772e 0x317cc6d 0x2b1e3f4 0x2b1f97b 0x2b2382f 0x26f1f7b 0x356182c 0x3561795 0x3564b2f 0x35648bb 0x356bffb 0x356487c 0x1e50f4 0x356bffb 0x1e4deb 0x1e5787 0x356c548 0x1c17f3f 0x1c17a39 0x1c3a734 0x1c39f44 0x1c39e1b 0x356bc50 0x97efced9 0x97f006de)
libc++abi.dylib: terminate called throwing an exception
(lldb)

我需要在我的代码中添加一些东西来处理这种情况吗?

4

1 回答 1

0

就我而言,这是因为我在加载 webWiew 之前在 viewWillAppear 中调用了我的方法 scrollToId

- (void)scrolToID
{
    NSString *jsCall = [NSString stringWithFormat:@"window.location.hash='#%@'", currentID];
   [self.webView stringByEvaluatingJavaScriptFromString:jsCall];
}

它应该在 webViewDidFinishLoad 中调用

于 2013-10-27T15:13:32.003 回答