在UiWebView中输入文本时,iOS应用程序崩溃了

时间:2014-08-25 06:58:03

标签: ios objective-c uiwebview unrecognized-selector

在我的iOS(Objective C)应用程序中,我在UIView中加载一个UIWebView,当我点击webview中的文本字段时,它只会导致应用程序崩溃,如果我只是触摸文本字段输入一些关键字应用程序将崩溃。我能够在示例应用程序中打开webView,但它在我的项目中失败了。

我有用户对变量的强引用。错误是:

-[__NSCFSet keyboardWillShow:]: unrecognized selector sent to instance 0x8fa0140
2014-08-25 12:15:40.626 Travelara[1263:60b] *** Terminating app due to uncaught exception            'NSInvalidArgumentException', reason: '-[__NSCFSet keyboardWillShow:]: unrecognized selector    sent to instance 0x8fa0140'
*** First throw call stack:
(
0   CoreFoundation                      0x01c7a1e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x019778e5 objc_exception_throw + 44
2   CoreFoundation                      0x01d17243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3   CoreFoundation                      0x01c6a50b ___forwarding___ + 1019
4   CoreFoundation                      0x01c6a0ee _CF_forwarding_prep_0 + 14
5   Foundation                          0x0164a049 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
6   CoreFoundation                      0x01cd5f04 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
7   CoreFoundation                      0x01c2defb _CFXNotificationPost + 2859
8   Foundation                          0x01583e41 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
9   UIKit                               0x00af1625 -[UIInputViewTransition postNotificationsForTransitionStart] + 1004
10  UIKit                               0x00ae7562 -[UIPeripheralHost(UIKitInternal) executeTransition:] + 592
11  UIKit                               0x00ae9a79 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 929
12  UIKit                               0x00ae9e7e -[UIPeripheralHost(UIKitInternal) setInputViews:animated:] + 72
13  UIKit                               0x00ae9ec8 -[UIPeripheralHost(UIKitInternal) setInputViews:] + 67
14  UIKit                               0x00ae0fb1 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 1448
15  UIKit                               0x0079d8b4 -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 287
16  UIKit                               0x00b0a6b5 -[UIWebBrowserView assistFormNode:] + 265
17  UIKit                               0x0087e435 __47-[UIWebDocumentView(Interaction) performClick:]_block_invoke172 + 52
18  libdispatch.dylib                   0x02e784d0 _dispatch_client_callout + 14
19  libdispatch.dylib                   0x02e67439 _dispatch_barrier_sync_f_slow_invoke + 80
20  libdispatch.dylib                   0x02e784d0 _dispatch_client_callout + 14
21  libdispatch.dylib                   0x02e66726 _dispatch_main_queue_callback_4CF + 340
22  CoreFoundation                      0x01cdf43e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
23  CoreFoundation                      0x01c205cb __CFRunLoopRun + 1963
24  CoreFoundation                      0x01c1f9d3 CFRunLoopRunSpecific + 467
25  CoreFoundation                      0x01c1f7eb CFRunLoopRunInMode + 123
26  GraphicsServices                    0x034145ee GSEventRunModal + 192
27  GraphicsServices                    0x0341442b GSEventRun + 104
28  UIKit                               0x00637f9b UIApplicationMain + 1225
29  Travelara                           0x0007b34d main + 141
30  libdyld.dylib                       0x030ad701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我使用的代码是:     self.webview1 = [[UIWebView alloc] initWithFrame:CGRectMake(10,70,292,430)];

    self.webview1.backgroundColor= [UIColor whiteColor]; 
    self.webview1.userInteractionEnabled=true;
    self.webview1.multipleTouchEnabled=true;
    self.webview1.delegate=self;
   [self addSubview:self.webview1];

     self.url=@"https://www.google.co.in/";
    self.nsurl=[NSURL URLWithString:self.url];
    self.nsrequest=[NSURLRequest requestWithURL:self.nsurl];
    [self.webview1 loadRequest:self.nsrequest];

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

虽然源代码不足以做出准确的猜测,但看起来像你定义的那样

[[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(keyboardWillShow:) 
    name:UIKeyboardWillShowNotification object:nil];

获取有关键盘显示的事件事件通知但忘记定义功能

- (void)keyboardWillShow:(NSNotification *)aNotification {
    [self performSelector:@selector(readjustWebviewScroller) withObject:nil afterDelay:0];
}

请检查。