int 值未通过,无法识别的选择器发送到实例 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序
Posted
技术标签:
【中文标题】int 值未通过,无法识别的选择器发送到实例 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序【英文标题】:int value not passing, unrecognized selector sent to instance Terminating app due to uncaught exception 'NSInvalidArgumentException' 【发布时间】:2014-02-05 18:21:25 【问题描述】:我正在尝试在不同文件之间传递两个整数值,但出现标题中提到的错误。
此行出错:- (NSString *) 查找:(NSString *)in get:(int)dictio get1:(int)dictio1;
错误文件:
2014-02-05 13:27:48.019 MaisOui[4556:70b] Value of d: 10 d1: 0
2014-02-05 13:27:49.496 MaisOui[4556:70b] Value of d: 10 d1: 10
2014-02-05 13:27:56.405 MaisOui[4556:70b] -[MaisOuiDictionary lookup:]: unrecognized selector sent to instance 0x8c44d30
2014-02-05 13:27:56.409 MaisOui[4556:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MaisOuiDictionary lookup:]: unrecognized selector sent to instance 0x8c44d30'
*** First throw call stack:
(
0 CoreFoundation 0x0173f5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014c28b6 objc_exception_throw + 44
2 CoreFoundation 0x017dc903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172f90b ___forwarding___ + 1019
4 CoreFoundation 0x0172f4ee _CF_forwarding_prep_0 + 14
5 MaisOui 0x00003299 -[MaisOuiViewController textFieldShouldReturn:] + 313
6 UIKit 0x0091761f -[UITextField keyboardInput:shouldInsertText:isMarkedText:] + 357
7 UIKit 0x004054f3 -[UIKeyboardImpl callShouldInsertText:] + 271
8 UIKit 0x0040f7d0 -[UIKeyboardImpl addWordTerminator:afterSpace:elapsedTime:executionContext:] + 63
9 UIKit 0x0040f2ca -[UIKeyboardImpl completeAcceptCandidateBeforeAddingInput:executionContext:] + 1668
10 UIKit 0x0040eba6 __60-[UIKeyboardImpl addInputString:withFlags:executionContext:]_block_invoke + 53
11 UIKit 0x0093ee7e -[UIKeyboardTaskExecutionContext returnExecutionToParent] + 254
12 UIKit 0x0041244b -[UIKeyboardImpl acceptCurrentCandidateIfSelectedWithExecutionContext:] + 250
13 UIKit 0x0040eb69 -[UIKeyboardImpl addInputString:withFlags:executionContext:] + 451
14 UIKit 0x0040da2f -[UIKeyboardImpl handleStringInput:withFlags:executionContext:] + 248
15 UIKit 0x0041bc1f -[UIKeyboardImpl handleKeyWithString:forKeyEvent:executionContext:] + 633
16 UIKit 0x0041b766 -[UIKeyboardImpl handleKeyEvent:executionContext:] + 1808
17 UIKit 0x0041afbf __33-[UIKeyboardImpl handleKeyEvent:]_block_invoke + 51
18 UIKit 0x0093f3c8 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
19 UIKit 0x0093fa6f -[UIKeyboardTaskQueue addTask:] + 144
20 UIKit 0x0041af84 -[UIKeyboardImpl handleKeyEvent:] + 227
21 UIKit 0x0024440b -[UIApplication _handleKeyUIEvent:] + 330
22 UIKit 0x0038afa4 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
23 UIKit 0x0038afa4 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
24 UIKit 0x0038afa4 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
25 UIKit 0x0038afa4 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
26 UIKit 0x002442ba -[UIApplication handleKeyUIEvent:] + 84
27 UIKit 0x0024425e -[UIApplication handleKeyHIDEvent:] + 458
28 UIKit 0x0022c07c _UIApplicationHandleEventQueue + 2954
29 CoreFoundation 0x016c883f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
30 CoreFoundation 0x016c81cb __CFRunLoopDoSources0 + 235
31 CoreFoundation 0x016e529e __CFRunLoopRun + 910
32 CoreFoundation 0x016e4ac3 CFRunLoopRunSpecific + 467
33 CoreFoundation 0x016e48db CFRunLoopRunInMode + 123
34 GraphicsServices 0x036e49e2 GSEventRunModal + 192
35 GraphicsServices 0x036e4809 GSEventRun + 104
36 UIKit 0x00230d3b UIApplicationMain + 1225
37 MaisOui 0x00002c5d main + 141
38 libdyld.dylib 0x01d7d70d start + 1
39 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
#import "MaisOuiAppDelegate.h"
int main(int argc, char * argv[])
@autoreleasepool
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MaisOuiAppDelegate class]));
从文件到传递:
int d=0;
int d1=0;
文件传递给:
@interface MaisOuiDictionary : NSObject
- (NSString *) lookup: (NSString *) in;
- (int) dic : (int) dictio;
- (int) dic1 : (int ) dictio1;
@end
- (NSString *) lookup: (NSString *)in get:(int)dictio get1:(int)dictio1;
// if(dictio==10 && dictio1==10)
NSString *rv = [self.wordsE_S objectForKey: in];
if ( !rv )
return @"*** no translation ***";
return rv;
// return @"**nothing**";
谁能告诉我哪里错了。我尝试将所有值更改为 int * 和 NSInteger *,但仍然出现相同的错误。
【问题讨论】:
您可以在问题中添加完整的错误吗? 这些都没有任何意义。首先,发布准确且完整的错误消息。第二 - 哪一行代码导致了问题? 已编辑,请立即查看。 鉴于崩溃日志,请发布您对textFieldShouldReturn
的实现
我可能完全不在这儿,但- (NSString *) lookup: (NSString *)in get:(int)dictio get1:(int)dictio1;
应该是接口中定义的函数查找的实现吗?那为什么最后有分号,为什么定义与接口中定义的查找不匹配。
【参考方案1】:
你已经实现了这个方法
- (NSString*)lookup:(NSString*)in get:(int)dictio get1:(int)diction;
...但您似乎正在尝试调用此方法(已在您的界面中定义)
- (NSString*)lookup:(NSString*)in;
因为lookup:
的实现不存在,所以您会抛出异常。您需要:
-
在你的界面中声明
lookup:get:get1:
,并在textFieldShouldReturn:
而不是lookup:
中调用它
在您的实施中实施lookup:
这一切都归结为您调用了一个不存在的方法。关于 Objective C 中方法命名的说明可以在这里找到:Method Syntax in Objective C
【讨论】:
以上是关于int 值未通过,无法识别的选择器发送到实例 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序的主要内容,如果未能解决你的问题,请参考以下文章
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__NSArrayM itemName]:无法识别的选择器发送到实例
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSCFString objectForKey:]:无法识别的选择器已发送到实例