我一直在阅读很多类似的问题和答案,但仍然不太明白这里出了什么问题。
我正在尝试创建一个按钮以返回上一个视图,但我不断收到标题中提到的错误。有人可以告诉我我做错了什么吗?
UIImage *image = [UIImage imageNamed:@"listbutton.png"];
UIButton *listbutton = [UIButton buttonWithType:UIButtonTypeCustom];
listbutton.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );
[listbutton setImage:image forState:UIControlStateNormal];
[listbutton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:listbutton];
GoBack的:
- (void)goBack
{
[self.navigationController popViewControllerAnimated:YES];
}
错误:
2014-01-05 22:03:13.344 tablepractice [12509:70b] - [DetailViewController goBack:]:无法识别的选择器发送到实例0x8b72130 2014-01-05 22:03:13.348 tablepractice [12509:70b] *由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [DetailViewController goBack:]:无法识别的选择器发送到实例0x8b72130' * 第一次抛出调用堆栈:(0 CoreFoundation 0x017405e4 exceptionPreprocess + 180 1 libobjc.A.dylib
0x014c38b6 objc_exception_throw + 44 2 CoreFoundation
0x017dd903 - [NSObject(NSObject)doesNotRecognizeSelector:] + 275 3
CoreFoundation 0x0173090b __ 转发 + 1019 4 CoreFoundation 0x017304ee _CF_forwarding_prep_0 + 14 5 libobjc.A.dylib 0x014d5874 - [NSObject performSelector:withObject:withObject:] + 77 6 UIKit 0x002330c2 - [UIApplication sendAction:to:from:forEvent:] + 108 7 UIKit
0x0023304e - [UIApplication sendAction:toTarget:fromSender:forEvent:] + 61 8 UIKit 0x0032b0c1 - [UIControl sendAction:to:forEvent:] + 66 9 UIKit
0x0032b484 - [UIControl _sendActionsForEvents:withEvent:] + 577 10 UIKit 0x0032a733 - [UIControl touchesEnded:withEvent:] + 641 11 UIKit
0x0027051d - [UIWindow _sendTouchesForEvent:] + 852 12 UIKit
0x00271184 - [UIWindow sendEvent:] + 1232 13 UIKit
0x00244e86 - [UIApplication sendEvent:] + 242 14 UIKit
0x0022f18f _UIApplicationHandleEventQueue + 11421 15 CoreFoundation 0x016c983f CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15 16 CoreFoundation 0x016c91cb __CFRunLoopDoSources0 + 235 17 CoreFoundation 0x016e629e __CFRunLoopRun + 910 18 CoreFoundation
0x016e5ac3 CFRunLoopRunSpecific + 467 19 CoreFoundation
0x016e58db CFRunLoopRunInMode + 123 20图形服务
0x036e59e2 GSEventRunModal + 192 21 GraphicsServices
0x036e5809 GSEventRun + 104 22 UIKit
0x00231d3b UIApplicationMain + 1225 23 tablepractice
0x0000388d main + 141 24 libdyld.dylib
0x01d7e70d开始+ 1 25 ??? 0x00000001 0x0 + 1)libc ++ abi.dylib:以未捕获终止 NSException类型的异常
答案 0 :(得分:5)
[listbutton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
这需要更改为在选择器方法中不使用冒号:
[listbutton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
冒号表示有一个参数,而你的goBack方法没有参数。