[英]UIWebView inside Navigation Controller crashes when typing
I've spent a few hours searching for a solution to this problem but I can't even seem to find anyone who's experienced it, let alone a solution. 我已经花了几个小时寻找解决这个问题的方法,但是我似乎找不到任何经历过的人,更不用说解决方法了。
In my project, I have a main view controller that pushes a second view controller containing a UIWebView. 在我的项目中,我有一个主视图控制器,该控制器会推送另一个包含UIWebView的视图控制器。 Both view controllers are embedded in a navigation controller. 两个视图控制器都嵌入在导航控制器中。 The push segue and WebView are both hooked up using IB. 推送功能和WebView都使用IB连接。
The segue happens as expected and the web page loads and works fine until I try to type. segue按预期发生,并且网页加载并正常运行,直到我尝试键入为止。 Tapping on a text field brings up the keyboard, but the first key press crashes the app and gives the error: 轻击文本字段会弹出键盘,但第一次按键会导致应用程序崩溃并给出错误:
-[NSNull length]: unrecognized selector sent to instance 0x1899068
2014-02-06 04:37:19.550 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x1899068'
*** First throw call stack:
(
0 CoreFoundation 0x0174d5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014d08b6 objc_exception_throw + 44
...
This happens both in the Simulator and on device. 这在模拟器和设备上均会发生。 I'm particularly confused because I'm not doing anything remotely complex. 我特别困惑,因为我没有做任何复杂的事情。 In the view controller that contains the WebView, I have the following viewDidLoad: 在包含WebView的视图控制器中,我具有以下viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
}
and no other code. 没有其他代码。 Google is used as an example site here, but it happens on every site I've tried. Google在这里用作示例网站,但是在我尝试过的每个网站上都有。 The weird thing is that if I remove the segue and present the Web View without the parent Navigation Controller, everything works fine, so it seems like the nav controller has something to do with it. 奇怪的是,如果我删除了segue并在没有父级导航控制器的情况下显示Web视图,则一切正常,因此,似乎nav控制器与此有关。 As I said, the webView property is hooked up as an IB outlet. 就像我说的,webView属性被连接为IB插座。 I've also tried adding it programatically, but the outcome was the same. 我也尝试过以编程方式添加它,但是结果是一样的。 As far as I can tell nothing in my first view controller should have any effect on this; 据我所知,我的第一个视图控制器对此没有任何影响。 like I said it's a Storyboard segue from a button. 就像我说的那样,这是一个通过按钮进行的故事板选择 I can be sure sending length to NSNull is not anything I'm doing directly by myself, as I don't use the length selector anywhere in my code. 我可以确定将长度发送到NSNull并不是我自己直接执行的任何操作,因为我不在代码中的任何地方使用长度选择器。
Any help would be greatly appreciated. 任何帮助将不胜感激。
It was requested so the full error message is as follows: 已请求,因此完整的错误消息如下:
-[NSNull length]: unrecognized selector sent to instance 0x1899068
2014-02-06 05:18:29.607 AppName[859:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x1899068'
*** First throw call stack:
(
0 CoreFoundation 0x0174d5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014d08b6 objc_exception_throw + 44
2 CoreFoundation 0x017ea903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0173d90b ___forwarding___ + 1019
4 CoreFoundation 0x0173d4ee _CF_forwarding_prep_0 + 14
5 CoreFoundation 0x016cd95c CFStringGetLength + 140
6 CoreFoundation 0x016e1284 CFStringCompareWithOptionsAndLocale + 52
7 Foundation 0x010db634 -[NSString compare:options:range:locale:] + 175
8 Foundation 0x010db580 -[NSString compare:options:range:] + 69
9 Foundation 0x010eda59 -[NSString caseInsensitiveCompare:] + 80
10 UIKit 0x00454f48 -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 280
11 UIKit 0x00398ac9 -[UIResponder(Internal) _keyCommandForEvent:] + 312
12 UIKit 0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
13 UIKit 0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
14 UIKit 0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
15 UIKit 0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
16 UIKit 0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
17 UIKit 0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
18 UIKit 0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
19 UIKit 0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
20 UIKit 0x00252176 -[UIApplication handleKeyHIDEvent:] + 226
21 UIKit 0x0023a07c _UIApplicationHandleEventQueue + 2954
22 CoreFoundation 0x016d683f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
23 CoreFoundation 0x016d61cb __CFRunLoopDoSources0 + 235
24 CoreFoundation 0x016f329e __CFRunLoopRun + 910
25 CoreFoundation 0x016f2ac3 CFRunLoopRunSpecific + 467
26 CoreFoundation 0x016f28db CFRunLoopRunInMode + 123
27 GraphicsServices 0x036f29e2 GSEventRunModal + 192
28 GraphicsServices 0x036f2809 GSEventRun + 104
29 UIKit 0x0023ed3b UIApplicationMain + 1225
30 AppName 0x00003d3d main + 141
31 libdyld.dylib 0x01d8b70d start + 1
32 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
So I managed to fix this by not really doing anything. 所以我设法不做任何事情来解决这个问题。 What eventually fixed it was deleting the Navigation Controller that all the VCs were embedded in, then embedding them back in a Nav Controller. 最终解决的办法是删除所有VC都嵌入在其中的Navigation Controller,然后将它们重新嵌入Nav Controller中。 Now it works completely. 现在,它可以完全正常工作。 So I don't know if it was an errant setting or what. 所以我不知道这是一个错误的环境还是什么。
@deergomoo sorry for my first answer. @deergomoo对不起我的第一个答案。 I wash it as false. 我把它洗成假的。
So, what do you think about next example? 那么,您如何看待下一个示例? Is it similar to your project structure? 它与您的项目结构类似吗? I can't find crashes. 我找不到崩溃。
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navController=[UINavigationController new];
ViewController *viewController=[[ViewController alloc] init];
[navController pushViewController:viewController animated:NO];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
. 。
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds
style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
reuseIdentifier:nil];
cell.textLabel.text = @"Cell";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"didSelectRowAtIndexPath");
UIViewController *viewController = [UIViewController new];
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[viewController.view addSubview:webView];
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[self.navigationController pushViewController:viewController animated:TRUE];
}
@end
In my case I guess my tab bar controller had become corrupt in my storyboard. 就我而言,我猜我的标签栏控制器在情节提要中已损坏。 I had to remove all the view controller outlets from it. 我不得不从中删除所有的视图控制器插座。 Delete the tab bar controller. 删除选项卡栏控制器。 Clean the project. 清理项目。 Add a new tab bar controller and re-wire all the outlets. 添加一个新的标签栏控制器,然后重新布线所有插座。 Then I stopped seeing this crash. 然后我停止看到此崩溃。
I just mention it so it may help someone else. 我只是提到它,所以它可能会对其他人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.