[英]UIWebView inside Navigation Controller crashes when typing
我已经花了几个小时寻找解决这个问题的方法,但是我似乎找不到任何经历过的人,更不用说解决方法了。
在我的项目中,我有一个主视图控制器,该控制器会推送另一个包含UIWebView的视图控制器。 两个视图控制器都嵌入在导航控制器中。 推送功能和WebView都使用IB连接。
segue按预期发生,并且网页加载并正常运行,直到我尝试键入为止。 轻击文本字段会弹出键盘,但第一次按键会导致应用程序崩溃并给出错误:
-[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
...
这在模拟器和设备上均会发生。 我特别困惑,因为我没有做任何复杂的事情。 在包含WebView的视图控制器中,我具有以下viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
}
没有其他代码。 Google在这里用作示例网站,但是在我尝试过的每个网站上都有。 奇怪的是,如果我删除了segue并在没有父级导航控制器的情况下显示Web视图,则一切正常,因此,似乎nav控制器与此有关。 就像我说的,webView属性被连接为IB插座。 我也尝试过以编程方式添加它,但是结果是一样的。 据我所知,我的第一个视图控制器对此没有任何影响。 就像我说的那样,这是一个通过按钮进行的故事板选择 我可以确定将长度发送到NSNull并不是我自己直接执行的任何操作,因为我不在代码中的任何地方使用长度选择器。
任何帮助将不胜感激。
已请求,因此完整的错误消息如下:
-[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
所以我设法不做任何事情来解决这个问题。 最终解决的办法是删除所有VC都嵌入在其中的Navigation Controller,然后将它们重新嵌入Nav Controller中。 现在,它可以完全正常工作。 所以我不知道这是一个错误的环境还是什么。
@deergomoo对不起我的第一个答案。 我把它洗成假的。
那么,您如何看待下一个示例? 它与您的项目结构类似吗? 我找不到崩溃。
@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
就我而言,我猜我的标签栏控制器在情节提要中已损坏。 我不得不从中删除所有的视图控制器插座。 删除选项卡栏控制器。 清理项目。 添加一个新的标签栏控制器,然后重新布线所有插座。 然后我停止看到此崩溃。
我只是提到它,所以它可能会对其他人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.