大家好,我正在尝试创建一个布尔方法,该方法将在单击提交按钮时根据用户输入的字段返回值。
- (BOOL)checkuser:(NSString*)input
{
bool result = NO;
if ([input isEqualToString:@"test"])
{
result = YES;
}
else
{
result = NO;
}
return result;
}
我从我的程序中引用这个方法
else if ([Username checkuser] == YES)
{ // do something
}
带有以下警告“NSString”可能无法响应“-checkuser”
而且我不明白为什么我的程序此时会因以下错误而崩溃。
2011-03-22 22:57:25.942 分配 2[824:207]-[NSCFString checkuser]:无法识别的选择器发送到实例 0x4b7c050 2011-03-22 22:57:25.944 分配 2[824:207] * 终止应用程序到期未捕获的异常'NSInvalidArgumentException',原因:'-[NSCFString checkuser]:无法识别的选择器发送到实例0x4b7c050'*第一次抛出调用堆栈:(0 CoreFoundation 0x00db8be9 exceptionPreprocess + 185 1 libobjc.A.dylib 0x00f0d5c2 objc_exception_throw + 47 2 CoreFoundation 0x00dba -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x00d2a366 __转发+ 966 4 CoreFoundation 0x00d29f22 _CF_forwarding_prep_0 + 50 5 分配 2 0x00002958 -[Assignment_2ViewController SubmitbuttonPressed:] + 727 6 UIKit 0x002c1a6e -[UIApplication sendAction:to:from:forEvent:] + 119 7 UIKit 0x003to:forEvent:]-[UIKit sendAction:to:from:forEvent:] + 67 8 UIKit 0x00352647 -[UIControl(内部) _sendActionsForEvents:withEvent:] + 527 9 UIKit 0x003511f4 -[UIControl touchesEnded:withEvent:] + 458 10 UIKit 0x002e60d1 -[UIWindow _sendTouchesForEvent:] + 567 1371 UIKit 0x00ca -[UIKit 0x002] + 447 12 UIKit 0x002cc732 _UIApplicationHandleEvent + 7576 13 GraphicsServices 0x016eea36 PurpleEventCallback + 1550 14 CoreFoundation 0x00d9a064CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION+ 52 15 CoreFoundation 0x00cfa6f7 __CFRunLoopDoSource1 + 215 16 CoreFoundation 0x00cf7983 __CFRunLoopRun + 979 17 CoreFoundation 0x00cf7240 CFRunLoopRunSpecific + 208 18 CoreFoundation 0x00cf7161 CFRunLoopRunInMode + 97 19 GraphicsServices 0x016ed268 GSEventRunModal + 217 20 GraphicsServices 0x016ed32d GSEventRun + 115 21 UIKit 0x002d042e UIApplicationMain + 1160 22 Assignment 2 0x00001c04 main + 102 23 赋值 2 0x00001b95 start + 53 ) 在抛出“NSException”实例后调用终止程序接收到的信号:“SIGABRT”。(gdb)